Question
public class Clock { private int hr; private int min; private int sec; public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); }
public class Clock { private int hr; private int min; private int sec;
public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); }
public Clock() { setTime(0, 0, 0); }
public void setTime(int hours, int minutes, int seconds) { if(0 <= hours && hours < 24) hr = hours; else hr = 0;
if(0 <= minutes && minutes < 60) min = minutes; else min = 0;
if(0 <= seconds && seconds < 60) sec = seconds; else sec = 0; }
public int getHours() { return hr; }
public int getMinutes() { return min; }
public int getSeconds() { return sec; }
public void printTime() { if(hr < 10) System.out.print("0"); System.out.print(hr + ":");
if(min < 10) System.out.print("0"); System.out.print(min + ":");
if(sec < 10) System.out.print("0"); System.out.print(sec); }
public void incrementSeconds() { sec++; if(sec > 59) { sec = 0; incrementMinutes(); } }
public void incrementMinutes() { min++; if(min > 59) { min = 0; incrementHours(); } }
public void incrementHours() { hr++; if(hr > 23) hr = 0; }
public String toString() { String str = "";
if(hr < 10) str = "0"; str = str + hr + ":";
if(min < 10) str = str + "0" ; str = str + min + ":";
if(sec < 10) str = str + "0"; str = str + sec;
return str; }
From the code above, I need help with creating a child class called ClockChild. I need to create a constructor that calls the parents default constructor and an overloaded constructor that takes in hours, minutes and seconds and sets the member variables accordingly. I then need to create a printTime method, for the child. Now it will take in a parameter called typeOfClock. This will be an integer that will be either 12 or 24. This tells the function how to print the time, either in military time (the parents type, call the parent method) or in normal type (12-hour) 11:30pm or 9:09am.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started