This assignment is due Tuesday, October 20.
This assignment uses the material from Section 4.1. It is based on Practice Exercise 6 on page 255 at the end of Chapter 4. This assignment makes use of the files contained in this zip file.
Write a program called Hw4.java
to read a list of exam scores given as integers in the range 0 to 100. Display the total number of grades and the number of grades in each letter-grade category as follows: 90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and 0 to 59 is an F. Your program should also output the highest score. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, so do not use it in the calculations.)
For example, if the input is the following list of numbers
87 72 85 63 78 73 50 72 72 98 70 85 66 86 -1
then the output of your program should look exactly like this
Total number of grades = 14 Number of A’s = 1 Number of B’s = 4 Number of C’s = 6 Number of D’s = 2 Number of F’s = 1 The highest grade = 98
Write your program in such a way that your program does not prompt the user in any way for the input values! Your program should read exactly one integer per line of input from the user, but not ever prompt the user for the input. Why would you want to write a program that reads in data from a user but does not prompt the user in any way? The answer is a very important idea called "I/O redirection". A program like this assignment is meant to process data, but it can be very tedious and error prone to enter a lot of data into a program like this. It is better to first enter all the data into a data file, like the one called data.txt
in the zip file, and then have the program process the data stored in the file. You get a Java program to read its input from a data file (instead of from the keyboard) by running the Java program at the command-line is a special way.
In the zip file there is a program called TestIORedirection.java
. Compile this program. Then open a command-line window from the folder that holds the file TestIORedirection.class
and type, after the command prompt, the command
C:\hw4> java TestIORedirection < data.txt
That command runs the TestIORedirection
program and has the program read the data stored in the file data.txt
.
Turn in a zip file called CS123Hw4Surname.zip
(where Surname
is your last name) containing your version of Hw4.java
.
This assignment is due Tuesday, October 20.