Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Chapter 6, the class Clock was designed to implement the time of day in a pro

ID: 664620 • Letter: I

Question

In Chapter 6, the class Clock was designed to implement the time of day in a program. Certain applications—in addition to storing hours, minutes, and seconds—might require you to store the time zone. Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add the necessary methods and constructors to make the class func- tional. Also, write the definitions of the methods and the constructors. Finally, write a test program to test your class.(In java please)

Explanation / Answer

public class ExtClock extends Clock
{
    private String timeZone;

    public ExtClock()
    {
        setTime(0, 0, 0, "unknown");
    }
    public ExtClock(int hours, int minutes, int seconds, String zone)
    {
        super(hours, minutes, seconds);
        timeZone = zone;
    }
    public void setTime(int hours, int minutes, int seconds, String zone)
    {
        //    I think something should go here to represent
       //       the hours, minutes, and seconds...
       timeZone = zone;
    }

    public void setTimeZone(String zone)
    {
        timeZone = zone;
    }
    public String getTimeZone()
    {
        return timeZone;
    }
    @Override
    public String toString()
    {
        return (super.toString() + " " + timeZone);
    }
}//end of class

public class TestClock
{
    public static void main(String[] args)
    {
        //instantiate a few ExtClock objects
        ExtClock clockOne = new ExtClock(7, 30, 22, "Mountain");
        ExtClock clockTwo = new ExtClock();//tests default constructor
        ExtClock clockThree = new ExtClock(14, 7, 35, "Central");
        //test methods on ExtClock objects ?
      
        //print out the values of the ExtClock objects
        System.out.println(clockOne);
        System.out.println(clockTwo);
        System.out.println(clockThree);
    }//end of main
}//end of class