Objective: Identify and fix the compiler and logic errors in a program and to write simple programs using some of Java's available class, simple control structures, and arrays.
Due: Before the next class (Friday)
Create a directory for assign1
within
your cs209
directory.
Bookmark the Java API. Also bookmark the course schedule page, if you haven't already.
Save Assign1.java into
your assign1
directory.
This 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.
You may want to run this program with multiple command-line
arguments. Specifically, try running the program with and
without cow
as a command-line argument.
Save your output in files
called cow1
, cow2
,
etc.
The current 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 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 an average difficulty score
of 6.0 (which should be a class constant). Represent the
judges' execution scores as an array of floats or doubles.
You cannot assume that the array is sorted from
initialization. (Look at
the Arrays
class
and this
example for help.) Calculate the average score, as described
above. Display the judges' scores and the final score.
Example output:
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 in the
file scores.out
.
Your Java program (ReverseString
) should take in a
string from the command line (look
at example
using command-line arguments) and print the string backwards.
Use a String
as an accumulator for the
reverse of the original string. Go through the original string
character by character, from the end of the string to the beginning.
(Hint:
What String
method should you use?)
Alternatively, for 3 points extra credit, use
a StringBuilder
to accumulate the String
, since
the StringBuilder
is more efficient.
Example output for java ReverseString stars
:
stars backwards is srats.
If the user does not enter a string on the command line, print a useful error message.
Example output for java ReverseString
:
Error: Need a command-line argument.
Save the output from several runs of the program
in the file reverse.out
. After running the
program the first time, use >>
to put additional output into the same
file. For example:
java ReverseString stars > reverse.out
java ReverseString banana >> reverse.out
Copy your assign1
directory into your
turnin directory,
i.e., /home/courses/cs209/turnin/yourusername
.
For example:
cp -r assign1 /home/courses/cs209/turnin/sprenkles/
There is no printed part of this assignment.
You will be evaluated based on