COMP 110 Second Java Program: Defining Classes and Making/Using Objects due date: Wed, Nov. 24 by 11:59 pm (before you leave for break) OVERVIEW You will write a Java program that will compute grade averages for UNC students, and you will do it with objects. CLASSES You will use at least these two classes: Student, and HW7 (you may also wish to use class Prompter, and you may write other classes if you wish to in your program design). You will write class Student to contain information about the person (name, year in school, etc.), and about academics (like the grades). You will also write class HW7 to contain the required main method and act as a "driver" to create and manipulate the Student objects and use them to compute the requested stats. More on these classes later. INPUT Command Line: Your program will get two command line arguments, both integers. The first integer tells how many students you are dealing with (course size). The second integer tells how many grades a student has. You will need to check to make sure each integer given is greater than zero, but you can assume that the user will give integers (as opposed to doubles or a non-numbers). Keyboard: The rest of your input data will come from the keyboard. You can use the Prompter.prompt method I gave you, or build the keyboard code into your program as you wish. There will be two main times that input is needed. First, you will need to get student names, major, and year in school when the Student objects are created. The data that will be collected about each student is this: first name, last name, year, major first and last name are type String major is type String year is type int (and will have value 1, 2, 3, 4, or 5) Then later, in a "driver" section, the user will type an input value to select from a menu of actions. Many of the actions will be requests for the Student objects to compute information, but one selection will be to add grade information to all students; this will require keyboard input. Some other selections will also require keyboard input. MENU and OUTPUT After creating the student objects and loading them, your program will then enter a section I have called the "driver". In this section, the code will present the user with a menu of actions to select from. The menu should look something like this: Selection an action to perform: 0 - quit 1 - show class roster (showing grade average for each student) 2 - add an exam grade for all students 3 - show student information 4 - show class average 5 - show overall average for a specific major 6 - show overall average for students in specific class year 7 - show class "distribution"... how many A's, B's, C's, D's, F's Item 0 end the menu loop, the user is done Item 1 Show all student names. Next to each name print the current grade average. Item 2 Use Prompter.prompt to get get a grade for each student; a grade value is of type double. Item 3 User is asked for a student name For that student, show: name, major, year in school all individual grades grade average Item 4 No keyboard input needed Compute and print the overall class grade average Item 5 **extra credit** worth 3 pts User is asked for a major Compute and print the overall average for all students with that major. No names, just the average Item 6 **extra credit** worth 2 pts User is asked for a year in school (int) Compute and print the overall average for all students with that class year. No names, just the average Item 7 **extra credit** worth 5 pts No keyboard input needed Consider A, B, C, D, F to be defined as 10-pt ranges Compute and print how many A's there are, B's, C's etc. Just counts, no names MORE ON YOUR CLASSES The program source will be in at least two Java classes (let's say class name HW7 for the main class, and then class name Student. These will be in two separate files (let's say HW7.java and Student.java). The HW7 class will contain the required main method and can have any other methods you may want to write to help organize your code well and to use object of the Student class to get the requested results. The class Student will start this way: public class Student { It will have the data fields needed to save personal information String fName, lName, major; int year; It will have fields for storing grades double[] grades = new double[numGrades]; int curGrade=0; // this will tell you what is the index of the first // open grade slot The size numGrades comes from the second run argument. In class Student you will write several methods as well. You will appropriate accessors for the fields (getters and setters), and you will need methods to provide the summary information a user might want for a student -- like grade average. STRATEGY Your program will have several sections to it: (1) A part that gets the command line argument so you know how many students to process (with the error check). (2) A section that creates the collection of student objects. This section will read in data from the keyboard... create an object for each new student, and will save the user-supplied info into the student object. Then repeat until all students are created and info-loaded. (3) A section that loops until the user wants to end; the loop will print a menu of selections, let the user select one and then compute the information requested by the selection. One of these selections will be to quit the menu loop. The way to do part (3) is to add one menu function at a time. Make the menu be handled by a switch statement, and each case in the switch should call some method to do that action. You can them add code one method at a time as you grow the menu. ERROR CHECKING You are expected to do some error checking. When the command line arguments are read, you may assume the user gives integers, but you need to make sure they are integers greater than 0. Do other error checking as appropriate. For example, when you read grade information from the keyboard, you may assume the user gives a valid double, but you must check to make sure it lies between 0.0 and 100.0. Similarly, when numbers are input that should be integer make sure the integers are not less than 0. Do whatever checking you can think of that makes sense. EXTRA CREDIT The last three actions in the menu (items 5, 6, and 7) are not required, but can be done for a total of 10 pts extra credit. HEADER In each java source file, put this header as a Java comment: /* ========================================== ONYEN: jqpublic NAME: John Q. Public ASSIGNMENT: A7 CLASS: COMP 110-004 fall 2010 INSTRUCTOR: Stotts ========================================== */ FINAL THOUGHTS Remember to use good programming style... use named constants where appropriate, choose meaningful variable names, have a beginning block comment as well as smaller comments throughout, design a clear algorithm, make it all indented and readable.