Program3.doc

advertisement

COP 2551

Summer 2004

Programming Assignment #3

Objectives:

To obtain input from the keyboard using the InputStreamReader and

BufferedReader classes .

To create a separate class in addition to the driver class that contains the main() method.

To instantiate an object from a class other than the driver class.

To format output by creating a String object in a toString() method.

To display information about an object instantiated from the class containing the toString() method.

To gain experience with conditional and looping statements.

Assignment:

You are to design and implement a Java application that prompts the user to enter a student's first name, middle initial and last name. You are to have a separate prompt for each of the three parts of the name. Next, prompt the user to enter the number of quizzes the student has taken. Then begin a loop in which you will prompt the user to enter quiz grades.

As each grade is entered, keep a running sum (the grades themselves do not need to be saved). Also, keep track of the lowest grade entered thus far. Note that the number of quizzes entered can vary from one execution of the program to the next. After exiting the loop, the lowest grade is to be dropped, the average of the remaining grades is to be computed and the student's name, quiz average, and an appropriate message are to be displayed as illustrated below:

Higbee, Paul N.

===============

Average = 74.0

Not too bad!

Where the name is formatted as shown above and the average is to be displayed accurate to tenths . The following are examples of messages that might be

displayed based on the student's quiz average. Do not use these messages; rather make up your own .

100 Show Off!

90-99.9 Excellent Performance!

80-89.9 You Did Very Well!

70-79.9 Not Too Bad!

60-69.9 Need to Study More!

<60 See You Next Semester!

Your program is to consist of a driver class named

Grades that contains the main() method and a

ComputeAverage class that will contain the methods required to obtain a student’s name and quiz grades, compute the quiz average ( the lowest quiz grade is to be dropped ), and display the results. You are to create a toString() method in the ComputeAverage class to assist in display of the results. The invocations of print() or println() methods required to display the output are to be in the main() method.

There will be demonstrations of the Grades.class

and

ComputeAverage.class

file in class.

Your program should:

Obtain the input from the keyboard. Do not use the keyboard class described in your text.

Rather, use the InputStreamReader and

BufferedReader classes discussed in the Blackboard

Course Documents/Java Information/Java

Input/Output Folder and demonstrated in the

CircleStats class that you will find in the

CircleStats.java

file located in the Program3 public subdirectory.

No Exception (error) checking is required for this program. However, you will probably need to use the throws IOException clause at the end of each method header.

Use a switch statement to determine the message to display (which depends upon the average).

Use the DecimalFormat class to format output of the average score.

Use String class methods and the concatenation operator to assist in formatting the student's name as shown when you execute the demo program.

Note the double underline that exactly fits under the name. The formatting of the display should be accomplished in the toString() method.

Your programming style should adhere to the design guidelines in Appendix G of your text and class demonstrations.

As with past programs, you are to turn in a shared subdirectory that has your userid as its name. In that subdirectory you are to have only the source code for your program in files named Grades.java

and

ComputeAverage.java. In Addition, you are to turn in a folder ( not a notebook ) that includes the following material.

1.

Your name, date, class and section number and

Program3 on the cover.

2.

A printout of your java code for both classes.

3.

A UML class diagram showing the two classes involved in the Program3 project.

4.

A flowchart for any method that uses conditional or looping statements (e.g. if/then, while, etc.)

5.

A brief description of any problems you had creating the program, what you did to solve those problems, and any unresolved problems.

6.

A description of how you tested the program. a.

The data values you entered. b.

The results you obtained. Were the results always what you expected or did you need to modify your program?

7.

A statement of whether or not you did the extra credit modification to the main() method.

Be sure to verify that your directory is “shared” correctly and contains your source code. After turning your assignment in, verify that it has been received (do man turnin at the Linux prompt to see the turnin manual pages that explain how to verify turnin). Late assignments will not be accepted. Programs that do not compile will receive a grade of zero.

You may earn a 10% bonus if you create a loop in the main() method that allows the user to indicate a desire to either input data for another student or exit the program. This will be demonstrated in class.

The assignment code is higbee.cop2551_43.p3 . The program is to be created on Osprey. It is due on Thursday, June

17th at the start of class . Since late assignments will not be accepted – turn in whatever you have completed for part credit.

Paul Higbee

Download