1. Create a class hierarchy for clocks sold in a \"Clock Shop.\" This hierarchy
ID: 3598978 • Letter: 1
Question
1. Create a class hierarchy for clocks sold in a "Clock Shop." This hierarchy should have 3 levels, with "Clock" at the top level.
2.Create a class for a generic clock and child classes extending the generic clock as required for your hierarchy (create further child classes from your child classes as needed).
3.Create the following public methods and set them at the appropriate places in the class hierarchy (we want to use inheritance). The Clock class (and perhaps some of its children) should be abstract. Thus, if you have no need to define a method at the top level(s), make the method abstract and override the methods as necessary
1.buyClock
2.sellClock
3.cleanClock
4.setClock
5.repairClock
4.Add at least one method that is unique to each child class.
5.Add code to each method that prints a message telling its function (e.g., "Cleaning Clock" or "Cleaning Grandfather Clock" and from which class/method it is being called (e.g., "called from class "Grandfather [extends Clock], method cleanClock".
6.Create instances of each non-abstract child object and invoke the methods common to all as well as the methods unique to each. Declare the data type of the object as Clock. For example:
Explanation / Answer
Main.java
Clock.java
AnalogClock.java
DigitalClock.java
RolexWatch.java
AppleWatch.java
BadWatch.java
Run Main.java. You can see the sample output like this.
[Clock] buying clock...
[Clock] selling clock...
RolexWatch [extends AnalogClock [extends Clock]] cleaning clock...
[Clock] buying clock...
[Clock] selling clock...
AppleWatch [extends DigitalClock [extends Clock]] setting clock...
[Clock] buying clock...
[Clock] selling clock...
RolexWatch [extends AnalogClock [extends Clock]] cleaning clock...
BadWatch [extends RolexWatch [extends AnalogClock [extends Clock]]] repairing clock...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.