CS 12300 - Programming Assignment 5

This assignment is due Monday, November 19.

This assignment makes use of the files contained in this zip file.

Write a program called Hw5.java to read a list of grades given as integers in the range 50 to 100. For this assignment, grades are classified according to the following grading scale.

A+ 97 - 100
A 93 - 96
A- 89 - 92
B+ 85 - 88
B 81 - 84
B- 77 - 80
C+ 73 - 76
C 69 - 72
C- 65 - 68
D+ 61 - 64
D 57 - 60
D- 53 - 56
F 50 - 52

Your program should look for a negative grade as a sentinel value to indicate the end of the list of grades. (The negative value is used only to end the loop, so do not use it in the following calculations.)

After your program reads the list of grades, your program should display the total number of grades, the number of grades in each letter-grade category, the highest grade score and the lowest score. Your program should also draw a bar graph of the distribution of all the grades.

For example, if the input is the following list of numbers

87
72
85
63
78
73
51
72
72
98
70
90
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 A's  = 0
Number of A-'s = 1
Number of B+'s = 3
Number of B's  = 0
Number of B-'s = 1
Number of C+'s = 1
Number of C's  = 4
Number of C-'s = 1
Number of D+'s = 1
Number of D's  = 0
Number of D-'s = 0
Number of F's  = 1
The highest grade = 98
The lowest grade = 51
   0    5    10   15   20   25   30   35   40   45   50   55   60   65   70   75   80   85   90   95   100%
   |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A+ *******
A
A- *******
B+ *********************
B
B- *******
C+ *******
C  *****************************
C- *******
D+ *******
D
D-
F  *******

For each letter letter-grade category, its bar graph represents the percentage of the total grades in that category. Each asterisk in the bar graph represents 1%. Notice that there are 3 B+'s out of 14 grades which is (approximately) 21% of the total number of grades and there are 21 asterisks in the bar graph for B+.

In the assignment's zip file there are some files that let you test your program. Make sure your solution file Hw5.java is in the unzipped hw5 folder and compile your Hw5.java file to produce Hw5.class. Then use your mouse to double-click on the file run_test_script.cmd. That causes a window to pop up that runs your program using input from the file test_data.txt. There should not be any error messages in the pop up window. The output from running your program will be in a newly created file called test_script_output.txt. Your output should look exactly like the contents of the file test_script_output_correct.txt from the assignment's zip file.

In the assignment's zip file there is a sub-folder, demo_program, that contains files that give you another way to test your program. If you double click on either run_random_test_data.cmd or run_curved_test_data.cmd, they will produce a new data file containing random grades and then run a demo version of this assignment on the random data. If you copy that data file to the hw5 folder and double click on run_test_script.cmd, then you can compare your program's output with the demo program's output. Your program's output should always be exactly like the demo program's output.

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 test_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 in a special way that uses "I/O Redirection".

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:\hw5> java TestIORedirection  <  test_data.txt

That command runs the TestIORedirection program and has the program read the data stored in the file test_data.txt. The "<" character in the command-line is the "input redirection operator".

Turn in a zip file called CS123Hw5Surname.zip (where Surname is your last name) containing your version of Hw5.java.

This assignment is due Monday, November 19.