Skip to main content.

Assignment 2: Command-line Arguments, Control Structures, and Arrays

Objective: Practice with command-line arguments, conditionals, loops, and arrays.

Due: Sunday at 11:59 p.m.

Set Up

Cloning the Repository

In your terminal, go to the directory where you are keeping your repositories for CSCI209. Clone the repository for this assignment. Add your name to the README file.

Debugging a Program (40)

Assign2.java program contains at least 5 errors. Some are compiler errors that the compiler will catch. Others are logic errors that the compiler won't catch.

Comment out the original code and explain the cause of the error. Then, correct the code. Strive for the shortest number of changes and smallest amount of change to fix the problem.

You may want to run this program with multiple command-line arguments. For example, try running the program with and without cow as a command-line argument.

Note that this problem is also reviewing some ideas from previous classes. There are two slides (and the example programs they reference) we didn't talk about that are probably helpful.

Demonstrate that your fixed code works correctly. Save good examples of your output in files called cow1, cow2, etc. Add all your test output files to the repository.

Example run with expected output: java Assign2 cat dog bird

The length of command-line args is 3
You have more than 2 arguments.
arg[0] is cat with length 3
arg[1] is dog with length 3
arg[2] is bird with length 4
The sorted command-line arguments are 
    bird
    cat
    dog
You don't have a cow, man.

Submitting Your Assignment

Submit your assignment by pushing the code, output files, and README.md to GitHub.

Great! You got it working! Before you submit, review your code. Is your code written in an (relatively) understandable way? Any extra code that you no longer need? Do you have appropriate comments?

Checking your work

It is recommended that you [re?]clone your project in a new directory, and then make sure that you can compile and run your programs. (This is, afterall, exactly the process that I'll use.)

Grading (40 pts)

You will be evaluated based on