Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Create a subclass of the Student class called Undergraduate. Create a new Undergraduate object in the StudentApp class with the following details: TIP: Public

java image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Create a subclass of the Student class called Undergraduate. Create a new Undergraduate object in the StudentApp class with the following details: TIP: Public methods in the parent class are inherited and can be used by a child ID (auto-gen) Object u1 Name Barry Allen 30 Print the details of the Undergraduate object ut using the toString() method. What do you observe? Where did the state that is printed come from? e.g. setName(..) Answer: 6. Now, add the following features to your Undergraduate class: a. Attributes: minor (String), major (String). credits (int) b. Accessors and mutators as necessary for each attribute c. A default no-argument constructor for the Undergraduate class. 7. Create and/or modify the following Undergraduate objects in the StudentApp class: Object Name Major Minor Credits ut u2 u3 Barry Allen John Rambo Ellen Ripley ID (auto-gen) 30 40 50 Forensics Conflict Analysis Astrobiology Athletics International Affairs Conflict Analysis 20 15 8. Print the details of the Undergraduate objects u1, 2, 3 using the toString() method. What do you observe? Did all of the state print properly? Why not? Answer: 9. Let us now refine the toString() method in the Undergraduate class. Write a toString() in the Undergraduate class which returns the full details of an Undergraduate object (ID, name, fees, graduated, major, minor, credits). This method should call the toString() method inherited from the parent class (Student) to achieve this. TIP: Invoking a parent method from a child class Super methodName) 10. Run the StudentApp class again. What do you observe? Did all of the state print properly this time? How does it differ for the objects s1 s2 compared to u1,u2, u3? Answer: Page 2 of 4 Bonus Question: Comment off both of the toString() methods in the Undergraduate and Student classes. Run the Student App class again. Explain why the code still works and the meaning and origin of the output. 11. Overload the constructor of the Student class as follows: public Student(String name) The overloaded constructor should still set the state as in the original constructor. 12. Compile and run the StudentApp class. Did it work? Did you have to change the code for the Student objects s1 and s2 in the StudentApp class to suit the new constructor? Why or why not? Answer: 13. What happens when you compile your Undergraduate class? Which of the superclass constructors do you think is called by the Undergraduate constructor? Answer: 14. Comment off the no-argument constructor in the Student class. Observe the (compilation) error generated in the Undergraduate class. Explain why this happens. Explain how it can be fixed. (remove your commented code when finished Answer: 15. Create a subclass of the Student class called Postgraduate with the following: a. Attributes: supervisor (String), thesis Title (String), status (String) b. A constructor that accepts a name, supervisor and thesis Title c. A mutator for status d. The default status for a student is full-time. TIP: Invoking a parent constructor from a child Note: Do not change the access modifiers of the Student class from private. You need to invoke the appropriate Student class constructor in order to set the name. superparameter 1...) 16. Create two Postgraduate objects in the StudentApp class with the following state Object Name p1 John McClain p2 Brian Mills ID 60 70 Supervisor Prof. Asp Pirin Dr. No Kia Thesis Title H ow to Die Hard Mobile Usage Patterns in Hostage Situations 17. In the Postgraduate class, refine the inherited toString() method from the Student so that the full details of a Postgraduate object are returned. Print the details of the Postgraduate objects p1 and p2 in the StudentApp class using your refined toString() 18. Override the method calculateFees() in the Undergraduate class so that Undergraduate tuition fees are calculated based on the number of credits. Each credit costs $200.00 19. Override the method calculateFees() in the Postgraduate class so that part-time Postgraduate tuition fees amount to $1,325.00 full-time Postgraduate tuition fees amount to $2,650.00 20. Change the status of the Undergraduate and Postgraduate objects in the StudentApp class as follows: a. John McClain: full-time b. Brian Mills: part-time c. Barry Allen: full-time d. John Rambo: 25 credits e. Ellen Ripley: 20 credits Calculate their fees, and print their details once more. What do you observe? TIP: Overriding a method in a child class is the same as replacing the method inherited from the parent class: the same method signature is used Answer: 21. What happens when you invoke the calculateFees() method on the Student objects s1 and s2

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_2

Step: 3

blur-text-image_3

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

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

Students also viewed these Databases questions