I want to represent time with my time class. I can't use get and set methods.Only I can use listed methods on the code.But it doesn't work. It returns 0:0:0.
public int addHours(int hours) { if(hours>=0&&hours<=23) { return hours; } return 0; } public int addMinutes(int minutes) { if(minutes>=0&&minutes<=59) { return minutes; } return 0; } public int addSeconds(int seconds) { if(seconds>=0&&seconds<=59) { return seconds; } return 0; } public String showTime() { return hours+":"+minutes+":"+seconds; } }
add...-methods don't add anything. Why are they called "addSeconds" and "addMinutes"? You should either refactor the code to actually add the value or rename the methods.this.hours=hoursotherwise their values will not be saved