+ 1

Please help me!!! I'm stuck in the abstract classes

Hello everybody, Currently i'm trying to complete the online JAVA course on MOOC.FI and i'm complete lost in the following syntaxes: How they switched the following code : public class Main{ public static void main(String args[]){ ClockHand hours = new ClockHand(24); ClockHand minutes = new ClockHand(60); ClockHand seconds = new ClockHand(60); while (true) { // 1. Printing the time System.out.println(hours + ":" + minutes + ":" + seconds); // 2. Advancing the second hand seconds.advance(); // 3. Advancing the other hands when required if (seconds.value() == 0) { minutes.advance(); if (minutes.value() == 0) { hours.advance(); } } } } } public class ClockHand { private int value; private int limit; public ClockHand(int limit) { this.limit = limit; this.value = 0; } public void advance() { this.value = this.value + 1; if (this.value >= this.limit) { this.value = 0; } } public int value() { return this.value; } public String toString() { if (this.value < 10) { return "0" + this.value; } return "" + this.value; } } to this one : public class Main{ public static void main(String args[]){ Clock clock = new Clock(); while (true) { System.out.println(clock); clock.advance(); } } } public class Clock { private ClockHand hours; // what does it mean this??? private ClockHand minutes; private ClockHand seconds; public Clock() { this.hours = new ClockHand(24); // what does it mean this??? this.minutes = new ClockHand(60); this.seconds = new ClockHand(60); } public void advance() { this.seconds.advance(); if (this.seconds.value() == 0) { this.minutes.advance(); if (this.minutes.v

29th Aug 2021, 7:40 AM
Remus Tanasa
2 Antworten
+ 2
The first //what : Initial a ClockHand variable. Second //what : In this function, the previous variable is assign to a new obj of type ClockHand.
29th Aug 2021, 8:09 AM
Elia
Elia - avatar
0
The first what: the variable shoudn t be initialize with types?(int, String erc) Why they initialize with Private ClockHand hours instead of int hours?
29th Aug 2021, 9:29 AM
Remus Tanasa