Question: JAVA HW College Class includes : 3 variables / properties private String name; private int age; private String major; The rules have been established but

JAVA HW
College Class includes :
3 variables/properties
private String name;
private int age;
private String major;
The rules have been established but have not been enforced by the college class. A scholar student's name and major must be non-null, the age of the scholar student must be at least 13, and the major of the scholar student must be one of the majors listed below:
public static final String[] majors ={
"Computer Engineering", "Mechanical Engineering",
"Electrical Engineering", "Biomedical Engineering",
"Chemical Engineering", "Aerospace Engineering",
"Civil Engineering", "Physics", "Mathematics", "Biology",
"Chemistry", "Environmental Science", "Robotics Engineering",
"Materials Science", "Nuclear Engineering", "Biochemistry",
"Geology", "Astronomy", "Statistics", "Computer Development"
}
Make sure to pass each exception an error message explaining why the exception happened. All of the exception constructors can receive a String as a parameter. Secondly, you should have 2 methods in theCollegeclass should throw exceptions when they get invalid arguments.
anaddOnToAgemethod should throw an exception when it has passed a non-positive value.
public void addOnToAge(int newAge){
this.age = this.age + newAge;
}
anmajorChangemethod should throw an exception when passed an invalid major (one that is not in the list above).
public void majorChange(String major){
this.major = major;
}
Also, make sure to pass each exception an error message explaining why the exception happened. All of the exceptions constructors can receive a string as a parameter. Finally, fill out theavAgemethod below, that receives an array of scholar students as a parameter and returns, as a double, the average age of those scholar students.Watch out for the null Student objects. Your method should use atry and catch to avoid the NullPointerException caused by attempting to access the age of a null scholar student. Null scholar students should not count towards the average age.
public static double avAge(Student[] students){
return 0.0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!