Question: JAVA HW College Class : 3 Properties private String name; private int age; private string major; The rules have been established but has not been
JAVA HW
College Class :
Properties
private String name;
private int age;
private string major;
The rules have been established but has not been enforced by the college class. A scholar student's name and major must be nonnull, the age of the scholar student must be at least 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",
"Chesical Engifieering", "Aefospace Engifeerifg",
"Civil Engineering", "Physics", "Math", ielogy",
"Chemistry", "Envifon#ental Science", "Robotics Engineering",
"Materials Science", "Nucleaf Engineefifg", "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 methods in the College class should throw exceptions when they get invalid arguments.
an addOaToAge, method should throw an exception when passed a nonpositive value.
an majorChange method should throw an exception when passed an invalid major one that is
not in the list above
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 the avAge method 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 a try 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
