0
Consider the following java class definition: public class time { private int second; // from 1 to 60
private int minute; // from 1 to 60 private int hour; // from 0 to 23 public void decrease (); // move to previous second } a) Implement a constructor that initialises new objects of time class to be set to the 22:45:00. b) Implement setters for second, minute and hour c) Implement the increase method, which moves to the next second, ensuring that all data members are updated appropriately
4 ответов
0
constructor:
public Time(){ //your class should be un capitals
hour=22;
minute=45;
second=0;
}
0
public void getVar(){
return var;
}
public type Var(type var){
var=var;
}
The setters and getters are always the same, and they work even with if var and var in var=var have the same name.
0
public void increase (){
second++;
if (second>=60)
{
second=0;
minute++;
if (minute>=60){
minute=0;
hour++;
if (hour>=24){hour=0;}
}
}
}
0
Thanks for that...