Coder Social home page Coder Social logo

java-command-line-args-lab's Introduction

Command-Line Arguments Lab

Learning Goals

  • Practice passing arguments in via the command-line.

Instructions

Given the GroceryListDriver class again, modify the program to take in the file as a command-line argument instead of prompting the user for the file path.

Reuse the last lab to implement the read and write methods and then make sure that everything passes the unit tests again.

To implement the reading of command-line arguments, consider the following instructions and tips:

  • Modify the GroceryListDriver class.
    • Replace the Scanner object that is prompting the user for the file path with getting the file path via the command-line.
    • Refer to the Command-Line Arguments lesson as needed.
  • When running the GroceryListDriver class, pass in a file named grocery-list.txt.
  • Make sure the unit tests all still pass successfully.

Example Output

Consider the example output if no file is passed in via the command-line:

Please specify one file path as a command-line argument.

Consider the example output if we do pass in the file as a command-line argument:

Apples
Bananas
Cookies

Stretch

Along with passing the file path into the program via the command-line, also pass it the contents of the grocery list. If we were to implement this and then execute the Java program via the command-line, the command would look like this:

java GroceryListDriver grocery-list.txt Apples Bananas Cookies

java-command-line-args-lab's People

Contributors

kcleland0818 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

austinbaik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.