Question
Work out the following programming exercise 1 from Chapter 11 1. In Chapter 8, the class Clock was designed to implement the time of day
Work out the following programming exercise 1 from Chapter 11
1. In Chapter 8, the class Clock was designed to implement the time of day in a program. Certain applications in addition to 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 functional. Also write the definitions of the methods and the constructors. Finally, write a test program to test your class.
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
C:\Users\Dracatas\Documents\NetBeansProjects\ClassClock\src\TestClock.java:1: error: cannot find symbol class ExtClock extends Clock symbol: class Clock C:\Users\Dracatas\Documents\NetBeansProjects\ClassClock\src\TestClock.java:29: error: method does not override or implement a method from a supertype @Override C:\Users\Dracatas\Documents\NetBeansProjects\ClassClock\src\TestClock.java:32: error: cannot find symbol return (super.toString() + " " + timeZone); symbol: variable super location: class ExtClock 3 errors C:\Users\Dracatas\Documents\NetBeansProjects\ClassClock bproject\build-impl.xml:930: The following error occurred while executing this line: C:\Users\Dracatas\Documents\NetBeansProjects\ClassClock bproject\build-impl.xml:270: Compile failed; see the compiler error output for details. BUILD FAILED (total time: 1 second)
i am still learning java so i am not 100% sure or what to change or where to change it at
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