辅导案例-CST8132

  • July 30, 2020

CST8132 Object-Oriented Programming Lab 6: College System IV – Exception handling and Files Due Date: Week 9 – in own lab hours Marks: 10 marks (worth 5% of term mark) Demo: Demo your code and output to your lab professor during your own lab hours. Recommended Reading: Chapter 9, 10, 11, 15 of Deitel and Deitel, Java How to Program book Exercise In this lab, we create a few classes to simulate a college system. A college (name has to be entered by the user) has students registered with them (number of students has to be entered by the user). Each student has common attributes of a person (first name, last name, email, and phone number) and a gpa, which is calculated based on the marks obtained in various courses (number of courses can vary). We have fulltime students and part time students, each of them has different attributes. We also have student information in files, which we load into the simulator (use students.txt included with the question). The format of each line of the file is: • a char – either f or p – f represents full time student, p represents part time student • an int – Student Number • a string – First Name • a string – Last Name • a string – Email • a long – Phone Number • a string – Program Name • a double – GPA • for full time students, o a double – Tuition Fees • for part time students, o a double – Total Course Fees o a double – Credits In order to implement this system, you need to create the following classes: Person class (abstract) Instance variables: firstName(String), lastName(String), emailId(String), phoneNumber (long). Student class will be inheriting this class. So, think about the access specifiers for the instance variables. Constructor: do you need a no-arg constructor??? Think and decide! Abstract Methods: readInfo()- accepts a Scanner object, returns nothing printInfo() (both methods accepts nothing, returns nothing) Student class (extends Person class) Instance variables: studentNumber (int), programName (String), gpa (double). This class will be extended by FulltimeStudent and ParttimeStudent classes. Think about the access specifiers for these instance variables. Constructor: do you need a no-arg constructor??? Think and decide! Methods: 1. readInfo(): accepts a Scanner object, return nothing. Reads all student information and save them in the instance variables. As you are inheriting Person class, you have access to instance variables of that class. Not permitted to create local variables. In order to read marks, readMarks() method should be called from this method. Include the required annotation also. 2. readMarks(): accepts a Scanner object, return nothing. Reads number of courses, and then reads marks of all courses and stored them in a local double array. This method is always called from within the class (private method???) After reading the marks, this method will call calculateGpa(). 3. calculateGpa(): accepts a double array, returns nothing. This method is always called from within the class (private method???). This method calculates the gpa and store it in the instance variable gpa. (you can go with a simple calculation to get a score out of 4). 4. printInfo(): accepts nothing, returns nothing. This method prints details of a student using formatted output (printf). Include the required annotation also. 5. readFile(): accepts a Scanner object, returns nothing. This method reads all student and personal properties from the file. FulltimeStudent Class (extends Student class) Instance Variables: tuitionFees (double) Methods: 1. readInfo(): accepts a Scanner object, returns nothing. Calls readInfo() of the superclass. Then, this method reads tuition fees. 2. printInfo(): accepts nothing, returns nothing. Calls printInfo() of the superclass. This method then prints the tuition fees. 3. readFile(): accepts a Scanner object, returns nothing. This method reads specific information of full time student from the file. ParttimeStudent Class (extends Student class) Instance Variables: courseFeesTotal (double), credits (double) Methods: 1. readInfo(): accepts a Scanner object, returns nothing. Calls readInfo() of the superclass. Then, this method reads total course fees and credit hours. 2. printInfo(): accepts nothing, returns nothing. Calls printInfo() of the superclass. This method then prints the total course fees and credit hours. 3. readFile(): accepts a Scanner object, returns nothing. This method reads specific information of part time student from the file. College Class Instance variables: name (String – to store the name of the college), []students (Student) (students is an array of Student) Constructor: Parameterized constructor gets a name that represents the name of the college and a number that represents the number of students in the college. This constructor sets name (the name of the college) and creates the students array. Methods: 1. printTitle(): prints the title and the header row of the output (See output) 2. ReadStudentsDetails(): accepts a Scanner object and returns -1 if the array is full, otherwise returns the number of students in the array. The purpose of this method is to read details of all students (in a loop). For each student, you need to first read the type of the student – 1 for full time or 2 for part time. If the user enters a number other than 1 or 2, a message “Wrong student type” should be displayed. Once the student type is read correctly, the right student object should be created. (Here, the student object is taking the form of a FulltimeStudent or a ParttimeStudent, based on the type of the student…. Polymorphism). Then, readInfo() should be invoked to read details of all students. Based on the type of the student, the right method will be invoked. 3. printStudentDetails(): this method has a for loop that calls printInfo() for all students in the students[] array. 4. readFromFile(): This method accepts a Scanner object and returns -1 if the array is full, otherwise returns the number of students in the array. The method reads data from the file. It first reads the type of the student (Fulltime or Parttime), and based on that, corresponding object will be created (same process as in readStudentDetails(). In that method, user is entering the student type, but in this case, that information is also given in the file). Once the right object is created, readFile() method should be invoked. CollegeSystemTest class You need to update the driver class (test class), so that the user will get a chance to read from the file OR read from the keyboard, based on their choice. If the array is full, you need to show that message (check output). Algorithm for this class: Do the following until the user enters 3 for exit Show 3 options – Register students, display students, exit If the user wants to register students: Check whether your array has space. If no space, print a message If there is space, show two options – read from file, read from the keyboard Call corresponding method based on user’s choice If the user enters an invalid option, show that to the user. If the user wants to display existing students: Check whether any students are there in the array. If so, display details of those students If no students in the array, display message “No students in the array” If the user wants to exit, then exit gracefully by showing a nice message. For all user input and all file readings, you need to make sure that the program will not crash at any bad data (need to include exception handling). You need to include Javadoc also for this project. You will have only once Scanner object for the entire project, which you created in main, and you will be passing the same object to all the required methods. Format your code with proper indentation and other formatting. Your code should be properly commented. Test plan is not required for this exercise, but in future labs they will be required. Expected Output (green – user input) Enter name of College: Algonquin College Enter number of students: 5 1. Register Students 2. Display Students 3. Exit Enter your choice: 2 No students to display…. 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 1. Read from file 2. Read from the keyboard Enter your option: 1 1. Register Students 2. Display Students 3. Exit Enter your choice: 2 Algonquin College – List of Students ************************************ Program|Student#| Name| Email| Phone| GPA| Fees| Credits| CET| 1002| John Doe| [email protected]| 123456789| 3.94| 956.50| CST| 1005| Mark Williams| [email protected]| 124578963| 3.56| 980.00| 3.50| CP| 1008| Sam Thomas| [email protected]| 321654987| 3.95| 995.75| 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 1. Read from file 2. Read from the keyboard Enter your option: 2 Enter details of student ======================== 1 – Fulltime student 2 – Parttime Student Enter Student type: 1 Enter program name: CET Enter student number: 1015 Enter first name: Allen Enter last name: Sam Enter email Id: [email protected] Enter phone number: 25361436 Enter number of courses: 3 Enter mark 1: 98 Enter mark 2: 96 Enter mark 3: 95 Enter tuition fees: 987.56 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 1. Read from file 2. Read from the keyboard Enter your option: 2 Enter details of student ======================== 1 – Fulltime student 2 – Parttime Student Enter Student type: 2 Enter program name: CP Enter student number: 1020 Enter first name: Ann Enter last name: Thomas Enter email Id: [email protected] Enter phone number: ann ******Input mismatch exception***** Enter number of courses: 2 Enter mark 1: 98 Enter mark 2: 95 Enter total course fees: 963.25 Enter credit hours: 1.5 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 1. Read from file 2. Read from the keyboard Enter your option: 2 Array is full…. cannot add more students 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 Array is full…. cannot add more students 1. Register Students 2. Display Students 3. Exit Enter your choice: 2 Algonquin College – List of Students ************************************ Program|Student#| Name| Email| Phone| GPA| Fees| Credits| CET| 1002| John Doe| [email protected]| 123456789| 3.94| 956.50| CST| 1005| Mark Williams| [email protected]| 124578963| 3.56| 980.00| 3.50| CP| 1008| Sam Thomas| [email protected]| 321654987| 3.95| 995.75| CET| 1015| Allen Sam| [email protected]| 25361436| 3.85| 987.56| CP| 1020| Ann Thomas| [email protected]| 0| 3.86| 963.25| 1.50| 1. Register Students 2. Display Students 3. Exit Enter your choice: 1 Array is full…. cannot add more students 1. Register Students 2. Display Students 3. Exit Enter your choice: 3 Goodbye…. Have a nice day Submission Demonstrate your work to your lab professor. Grading Scheme Item Marks Person class (correct access specifiers, abstract methods) Requirement Student class (properly extended, correct access specifiers, 5 methods) 1 FullTimeStudent class (properly extended, correct access specifiers, 3 methods) 1 ParttimeStudent class (properly extended, correct access specifiers, 3 methods) 1 College class (correct access specifiers, constructors, 4 methods) 2 CollegeSystemTest class (main method with all required conditions) 2 Exception handling for all inputs 2 Comments (header info, comments, formatted code) 1

LATEST POSTS
MOST POPULAR

ezAce多年来为广大留学生提供定制写作、留学文书定制、语法润色以及网课代修等服务,超过200位指导老师为您提供24小时不间断地服务。