In the above loop, if you read a grade that is greater than 100 or less than 0 (and not the sentinel value), throw an exception. In the catch, ask the user to enter a correct value >= 0 and <=100. When the user enters a value within range, continue processing student’s grade with this new data otherwise continue asking the user to enter a correct value.
Write a program that reads a sequential file created by Notepad. Read the student’s name and grades. Calculate the grade average. Display the name and grade average to the screen and write it to a file. Create an exception class and use it in the Demo class.
Grade 1 (there is only one grade per line)
Sentinel value (the sentinel value is -999.9)
Repeat the above grouping for each student for any number of students
Functionality of Demo class:
Prompt user for file name. Obtain the name of the file to be read. If the file does not exist, continue to prompt the user to enter an existing file name until they enter one that exists. Do not use exception processing for this part.
The first line of the file is the student’s name. Each line up to but not including the sentinel value is a grade. The sentinel value indicates the end of a student’s grades. After the sentinel value the file may have either the end of file or another set of student’s grades. The number of grades is unknown. The number of students is unknown. Your program must read until is reaches the end of file. A sentinel value must always precede the end of file. (see file description above)
As the program reads the grades, accumulate a total and a count of the number of grades. When the sentential value is read, calculate an average. Display the student’s name and average on the screen. Also write this information to a file.
While in the above loop, if you read a grade that is greater than 100 or less than 0 (and not the sentinel value), throw an InvalidTestScore exception. In the catch, ask the user to enter a correct value >= 0 and <=100. When the user enters a value within range, continue processing student’s grade with this new data otherwise continue asking the user to enter a correct value.
Functionality of InvalidTestScore Class:
Create a class named InvalidTestScore. It should inherit from Exception. It needs a no argument constructor and a two argument constructor. The two argument constructor has parameters for the student’s name and invalid grade. There are no fields in this class. The no argument constructor displays the message Invalid test score. The two argument constructor displays the message The invalid test score for “student’s name“ is “student’s grade.” Use super to display this information.
Nikki Smith wrote:I think one of the other issues I noticed, is that the boolean method can only return true or false. But I need a way for int validNum to have the text file data stored to it, but only if the data is actually valid. I'm not sure if the boolean method will work for this.