Im at the last few steps in my homework and need some help understanding/doing the last two steps. The last two things I have to do are:
Create a toString() method that returns the value as a formatted time String. Remember that values less than 10 must be padded with zeroes. For example, midnight will look like this returned from getMilitaryTime(): 00:00:00. Use the String zeroPad(int) method to pad the numbers - see the code below. Use a StringBuffer object to build the String in the toString() method, calling zeroPad(int) as necessary. Create a main method and construct the following times and print the time using System.out.println(clock): Call the default constructor (no parameters)
hour: 0, minute: 94, second: 56
hour: 14, minute: 63, second: 64
hour: 98, minute: 76, second: -64
hour: 5, minute: 8, second: 1
hour: 23, minute: 59, second: 59
under just the println at the end I get the error :Syntax error on token "println", = expected after this token. I'm not sure if fixing this will help me move onto the next steps or not. Is what I have for the most part correct when it come to making the toString method?
So Far this is what I have:
//Create a new class called Clock
public class Clock {
public static void main(String[] args){
}
//Create three integer attributes for hour, minute and second.
//Always store the hour in military time.
private double MilitaryHour;
private double Minute;
private double Second;
// Create setters for the hour, minute and second values.
public double getMilitaryHour() {
return MilitaryHour;
}
public void setMilitaryHour(double militaryHour) {
if(militaryHour < 0 || militaryHour > 23)
this.MilitaryHour = (militaryHour % 24);
this.MilitaryHour = militaryHour;
}
public double getMinute() {
return Minute;
}
public void setMinute(double minute) {
if(minute < 0 || minute > 59)
this.Minute = (minute % 60);
this.Minute = minute;
}
public double getSecond() {
return Second;
}
public void setSecond(double second) {
if(second < 0 || second > 59)
this.Second = (second % 60);
this.Second = second;
}
public Clock(double MilitaryHour,double Minute,double Second) {
this.MilitaryHour = MilitaryHour;
this.Minute = Minute;
this.Second = Second;
}
/default
public Clock(){
this(0.0, 0.0, 0.0);
}
public String toString()
{
String result = "Hour: " + getMilitaryHour()+"Minute: " + getMinute()+ "Seconds:" + getSecond();
return result;
}
System.out.println("" + result.toString());
}