Skip to main content.

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

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

Due: Before the next class (Wednesday).

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.

Part 1: 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 note 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.

Save 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.

Part 2: Computing Olympics Gymnastic Score (35 pts)

The old system of scoring an Olympic gymnast is based on two separate panels of scores. The A panel judges the requirements, difficulty, and connections of a routine. The scoring starts at zero and then adds points accordingly. The B panel judges the execution of a routine, and the scoring starts at 10 with points deducted accordingly for execution and for any applicable violations such as stepping out of bounds or being over the time limit.

For each panel of six judges, the lowest and highest scores are dropped (to prevent judges from biasing the results) and then averaged. The two panels are then added together for the final score. A very good score will range in the 15s and 16s.

Your task: Write a Java class called OlympicScores. Assume the average difficulty score was already computed and is 6.0. Make it a class constant. (Where are class constants defined?). Represent the judges' execution scores as an array of doubles. You cannot assume that the array is sorted from initialization. (Look at the Arrays class and this example for help. The last problem may be helpful too.) Calculate the average score, as described above. Display the judges' scores and the final score in the format shown below.

Note that there is no input for this problem. You're just setting the values in the array.

Example output from executing java OlympicScores

Gymnastics Score
----------------
        Judges Execution Scores: 8.7 8.0 9.2 8.3 8.7 8.4
        Average Execution Score: 8.525
        Average Difficulty Score: 6.0
        The Final Score: 14.525

Save the output from one of your runs--where the scores are not sorted initially--in the file scores.out. Add the file to your repository.

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 (80 pts)

You will be evaluated based on