I just got done writing a 2-parameter constructor that meets the following specifications: /** * Creates a new digital clock with the time set at the given * hours and minutes. * * @precondition 0 <= hour <= 23 AND 0 <= minutes <= 59 * @postcondition getHour()==hour AND getMinutes()==minutes * * @param hour the hour to set for the time * @param minutes the minutes to set for the time */ I am now trying to initalize the instance variables to the appropriate paratmers listed above. So far this is my code: public class DigitalClock { private int currentHour; private int currentMinutes; public int getHour() { // Getter method for the currentHour int return currentHour; } public void setHour(int currentHour) { // Setter method for the currentHour int this.currentHour = currentHour; } public int getMinutes() { // Getter method for the currentMinutes int return currentMinutes; } public void setMinutes(int currentMinutes) { // Setter method for the currentMinutes int this.currentMinutes = currentMinutes; } public DigitalClock(int hour, int minutes) { // 2-parameter DigitalClock constructor (Parameters: hour and minutes) currentHour = hour; // Passes the value of currentHour to hour currentMinutes = minutes; // Passes the value of currentMinutes to minutes } } How do I initialize the instance variables to the appropriate paramters?
I just got done writing a 2-parameter constructor that meets the following specifications:
/**
* Creates a new digital clock with the time set at the given
* hours and minutes.
*
* @precondition 0 <= hour <= 23 AND 0 <= minutes <= 59
* @postcondition getHour()==hour AND getMinutes()==minutes
*
* @param hour the hour to set for the time
* @param minutes the minutes to set for the time
*/
I am now trying to initalize the instance variables to the appropriate paratmers listed above.
So far this is my code:
public class DigitalClock {
private int currentHour;
private int currentMinutes;
public int getHour() { // Getter method for the currentHour int
return currentHour;
}
public void setHour(int currentHour) { // Setter method for the currentHour int
this.currentHour = currentHour;
}
public int getMinutes() { // Getter method for the currentMinutes int
return currentMinutes;
}
public void setMinutes(int currentMinutes) { // Setter method for the currentMinutes int
this.currentMinutes = currentMinutes;
}
public DigitalClock(int hour, int minutes) { // 2-parameter DigitalClock constructor (Parameters: hour and minutes)
currentHour = hour; // Passes the value of currentHour to hour
currentMinutes = minutes; // Passes the value of currentMinutes to minutes
}
}
How do I initialize the instance variables to the appropriate paramters?
Step by step
Solved in 3 steps with 3 images