Question
This UJ program will ask the user for three students names, their major and their GPA. The program will then check the validity of the
This UJ program will ask the user for three students names, their major and their GPA. The program will then check the validity of the entered GPA. An exception will be thrown if an invalid GPA is entered using IllegalArgumentException class. After reading the required information, the student should create an object from the Student class and store it in the file as object type. The student needs to handle all the expected exceptions that might occur during the writhing or reading process from the file.
Note: there are specific Files associated with this lab exam.
Before you start do the following to set up you work environment:
Create new project called UJ
Create new class called Student and copy Student.java file
Create new class called UJDemo and copy UJDemo.java file
Task #1 implement the Serializable interface
Task 1.1: add the import of the required classes in order to be able to complete this task
Task1.2: In order to simply save objects to a file, you have to serialize these objects. Therefore, the Student class must implement the Serializable interface.
package uj; //add line for Task 1.1: //------------------------ //add line for Task 1.2: public class Student { //fields private String StudentName; private double GPA; private String major; //constructor public Student(String sn,double gpa,String m){ StudentName=sn; GPA=gpa; major=m; } //set methods public void setStudentName(String sn){ StudentName=sn; } public void setGPA(double gpa){ GPA=gpa; } public void setMajor(String m){ major=m; } //get methods public String getStudentName(){ return StudentName; } public double getGPA(){ return GPA; } public String getMajor(){ return major; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started