Consider the following java class definition: public class time { private int second; // from 1 to 60 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

21st Dec 2016, 3:52 PM
victor
4 Answers
0
constructor: public Time(){ //your class should be un capitals hour=22; minute=45; second=0; }
3rd Mar 2017, 7:22 PM
Qwerty
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.
3rd Mar 2017, 7:24 PM
Qwerty
0
public void increase (){ second++; if (second>=60) { second=0; minute++; if (minute>=60){ minute=0; hour++; if (hour>=24){hour=0;} } } }
3rd Mar 2017, 7:27 PM
Qwerty
0
Thanks for that...
29th Mar 2017, 8:07 PM
victor