Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Q3 (15 points). Implement the following UML class diagram in Java. Person protected name : String protected age : double public Person(String name, double

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Hello

Q3 (15 points). Implement the following UML class diagram in Java. Person protected name : String protected age : double public Person(String name, double age) public setName(String name) public setAge(double): void I Student private gpa: double public Student(String, double, double) public setGPA(double): void public setName(String name) InvalidAgeException public InvalidAgeException() public InvalidAgeException(String) 100% 1. Implement a user defined exception class called InvalidAge Exception. The class must have two constructors, a constructor that takes no parameters, and a constructor that takes a string message. These constructors should call the corresponding constructors from the super class java.lang. Exception. 2. Make the class Student as a subclass (i.e., extends) of the class Person. 3. Implement the methods of the class Person, as follows: i Constructor public void Person(String name, double age) This constructor initializes the protected fields thip name and this.age appropriately using the formal parameters of the constructor. II. public void setName(String name) This method sets the value for the protected field this name. . public void setGPA(double gpa) Sets the this.gpo attribute to the parameter gpa. public void setName(String name) This method MUST call the method setName() of the super class Person to set the filed this.name to the parameter name. 5. Implement a main method in the class Student, as follows: a. Add a try-catch blocks. The try block must include the following statements: 1. Create and instantiate an object of type Student with the values "Ali", 20,3.7. 2. Call the method setAge() on the object, where the actual parameter is 21. 3. Call the method setGPA() on the object, where the actual parameter is 3.78. I b. The catch block should catch InvalidAgeException exception, and it should call the method printStackTrace(). public void setAge(double age) This method throws an InvalidAgeException if the value of the parameter age is less than 18. Otherwise, it sets the field this.age to age. You should change the method signature to include the corresponding throws expression. 4. Implement the methods of the class Student, as follows: 1. public Student(String name, double age, double gpa) This constructor initializes the class attributes this.name and this.age, and, this.gpa appropriately. Note that some of these attributes are inherited from the Person class. public void setGPA(double gpa) Sets the this.gpa attribute to the parameter gpa. public void setName(String name)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions