Java class that models a very simple clock

Ok, you have 4 TODOs so let's break this down one by one.

SimpleClock constructor In your constructor's comment block it says you want the initial value of the clock to be 12:00:00AM. This would mean that your hours variable is 12, your minutes and seconds are both 0, and morning is set to true. Pretty small, 4 lines.

SimpleClock set This takes in 4 variables and sets them to the 4 variables that you have in your class. Again, small. 4 lines.

SimpleClock tick Here's the more complicated part. This method will increment your seconds variable by 1 when it is called. However you also want it to roll over, so if your seconds variable is equal to 60, you would want to set your seconds to 0 and increment your minutes by 1. Same when minutes is equal to 60 and incrementing your hours by 1. With hours it's slightly different. You don't want that over 12, and when it gets to 12 you want to make sure you switch your morning boolean from whatever it was to the opposite. This will be the largest method most likely with a few if statements.

SimpleClock time This method would take each of your variables and concatenate them together with a few colons to return a String of the time. Some things to watch out for here is if your minutes or seconds are under 10, you wouldn't want to just return 0 or 2 for the minutes. It would look weird if it returned as 1:0:0PM. As for your morning variable, if it is set to true, concatenate AM to your String, otherwise PM.

And those are your four TODOs. Shouldn't be too bad.

/r/javahelp Thread