An abstract class Clock has been provided with following instance variables 1. hours 2. mins 3. secs This class has an abstract method tick(). The responsibility of this method is to represent the...


An abstract class Clock has been provided with following instance variables
1. hours
2. mins
3. secs
This class has an abstract method tick(). The responsibility of this method
is to represent the passage of 1 second but what time is reached after
ticking depends upon whether the clock is 24 hrs or 12 hours.
You need to provide two subclasses namely Clock12 and Clock24 which represent the 12 and 24 hours clock respectively. Override the tick() mehtod in each of these classes so that 1 tick increases the time by 1 second and updates all values (hrs min and seconds accordingly).
On 24 hours clock 1 tick increases 1 second but consider the situation if the current time was 10:59:59 then ticking once will make it 11:00:00. You will have to consider all situations. 1 second can mean just increment in the seconds value. But if the seconds become 60 then you need to make it 0 again and increment mins instead and so on. Also, after 23:59:59 the time becomes 00:00:00.
On the 12 hours clock we will have to take an additional member am (boolean). If am is true then the 12 hours time is AM time otherwise its PM. Provide appropriate constructor for 12 hours clock to intialize all data members. Remember that in 12 hours clock the after 12:59:59 t AM The time becomes 01:00:00 PM. Similarly if originally its PM then it becomes AM.
Override the toString method for the 12 hours clock.


Use inheritance and abstraction and (polymorphism if required) in Java Programming. Also make its main class to call the methods properly and give the correct output. Also use String.format(String obj, args) in toString to return the formatted String.

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here