Hello! Please tell me how to correctly describe a comment to the race code with an example!

Thanks in advance!

package dragracing; /* ΠœΠ΅Ρ‚ΠΎΠ΄Ρ‹ интСрфСйса CarInterface */ public interface CarInterface { public int getId(); public void setId(int id); public String getDriver(); public void setDriver(String driver); public String getManufacturer(); public void setManufacturer(String manufacturer); public int getMaxSpeed(); public void setMaxSpeed(int maxSpeed); public String getModel(); public void setModel(String model); public int getVelocity(); public void setVelocity(int velocity); public long getCurrentSpeed(); public void setCurrentSpeed(long currentSpeed); public long getRunDistance(); public void setRunDistance(long runDistance); public int getRunTime(); public void setRunTime(int runTime); } /* Поля класса Car интСрфСйса CarInterface */ class Car implements CarInterface { private int id; private String manufacturer; private String model; private int velocity; private int maxSpeed; private long currentSpeed = 0; private long runDistance = 0; private int runTime = 0; private String driver; /* ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€ класса Car с Π²Ρ…ΠΎΠ΄Π½Ρ‹ΠΌΠΈ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ элСмСнта класса Car */ public Car(Car car) { this.id = car.id; this.manufacturer = car.manufacturer; this.model = car.model; this.velocity = car.velocity; this.maxSpeed = car.maxSpeed; this.driver = car.driver; this.currentSpeed = 0; this.runDistance = 0; this.runTime = 0; } /* ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€ класса Car с Π²Ρ…ΠΎΠ΄Π½Ρ‹ΠΌΠΈ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ */ public Car(int id, String manufacturer, String model, int velocity, int maxSpeed, String driver) { this.id = id; this.manufacturer = manufacturer; this.model = model; this.velocity = velocity; this.maxSpeed = maxSpeed; this.driver = driver; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getId Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния id */ public int getId() { return this.id; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setId Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния id */ public void setId(int id) { this.id = id; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getDriver Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния driver */ public String getDriver() { return this.driver; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setDriver Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния driver */ public void setDriver(String driver) { this.driver = driver; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getManufacturer Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния manufacturer */ public String getManufacturer() { return this.manufacturer; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setManufacturer Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния manufacturer */ public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getMaxSpeed Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния maxSpeed */ public int getMaxSpeed() { return this.maxSpeed; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setMaxSpeed Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния maxSpeed */ public void setMaxSpeed(int maxSpeed) { this.maxSpeed = maxSpeed; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getModel Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния model */ public String getModel() { return this.model; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setModel Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния model */ public void setModel(String model) { this.model = model; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getVelocity Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния velocity */ public int getVelocity() { return this.velocity; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setVelocity Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния velocity */ public void setVelocity(int velocity) { this.velocity = velocity; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getCurrentSpeed Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния currentSpeed */ public long getCurrentSpeed() { return this.currentSpeed; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setCurrentSpeed Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния currentSpeed */ public void setCurrentSpeed(long currentSpeed) { this.currentSpeed = currentSpeed; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getRunDistance Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния runDistance */ public long getRunDistance() { return this.runDistance; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setRunDistance Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния runDistance */ public void setRunDistance(long runDistance) { this.runDistance = runDistance; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ getRunTime Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния runTime */ public int getRunTime() { return this.runTime; } /* ΠœΠ΅Ρ‚ΠΎΠ΄ setRunTime Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ значСния runTime */ public void setRunTime(int runTime) { this.runTime = runTime; } } 

Second class

 package dragracing; /* ΠΈΠΌΠΏΠΎΡ€Ρ‚ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊ */ import java.util.HashMap; import java.util.Map; /* Поля класса Dragracing с Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΌΠΈ списакми */ public class Dragracing { private static Map<Integer, Car> cars = new HashMap<Integer, Car>(); /* БтатичСская константа trackLength */ private static final int trackLength = 402; /* БтатичСская ΠΌΠ΅Ρ‚ΠΎΠ΄ setCars Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ Π½Π΅ ΠΊΠ°ΠΊΠΎΠ³ΠΎ значСния с описаниСм Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ ΠΈ Π½Π°Π·Π²Π°Π½ΠΈΠΉ */ private static void setCars() { cars.put(1, new Car(1, "Toyota", "Celica", 6, 250, "Alex")); cars.put(2, new Car(2, "Dodge", "Viper", 7, 310, "Steve")); cars.put(3, new Car(3, "Porsche", "911", 9, 320, "Martin")); cars.put(4, new Car(4, "Dodge", "Challenger", 9, 250, "Andrew")); cars.put(5, new Car(5, "Toyota", "MR2", 5, 250, "Jim")); cars.put(6, new Car(6, "Honda", "NSX", 8, 280, "Hiroki")); cars.put(7, new Car(7, "Chevrolet", "Camaro", 8, 270, "Ricky")); cars.put(8, new Car(8, "Nissan", "GTR", 8, 310, "Kito")); cars.put(9, new Car(9, "Lamborghini", "Countach", 8, 300, "Linda")); cars.put(10, new Car(10, "VAZ", "2107", 8, 200, "Vasiliy")); } /* БтатичСская ΠΌΠ΅Ρ‚ΠΎΠ΄ refresh Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ Π½Π΅ ΠΊΠ°ΠΊΠΎΠ³ΠΎ значСния с Π²Ρ…ΠΎΠ΄Π½Ρ‹ΠΌΠΈ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ с условным ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ if */ private static void refresh(Car car, int time) { long maxSpeed = Math.round(car.getMaxSpeed()/3.6); long curSpeed = Math.round(car.getVelocity() * time); if(curSpeed > maxSpeed) curSpeed = maxSpeed; car.setRunDistance(car.getRunDistance() + curSpeed > trackLength ? trackLength : car.getRunDistance() + curSpeed); car.setCurrentSpeed(Math.round(curSpeed*3.6)); } /* БтатичСская ΠΌΠ΅Ρ‚ΠΎΠ΄ main Π½Π΅Π²ΠΎΠ·Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠΉ Π½Π΅ ΠΊΠ°ΠΊΠΎΠ³ΠΎ значСния с Π²Ρ…ΠΎΠ΄Π½Ρ‹ΠΌΠΈ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ с ΠΈΡΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ ситуациСй throws InterruptedException Ρ‚Π°ΠΊ ΠΆΠ΅ с Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΌ списком с Ρ†ΠΈΠΊΠ»ΠΎΠΌ for ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ boolean с Ρ†ΠΈΠΊΠ»ΠΎΠΌ while c условным ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ if */ public static void main(String[] args) throws InterruptedException { HashMap<Integer, Car> results = new HashMap<Integer, Car>(); setCars(); int runNum = 1; for(int i = 1; i < cars.size(); i++) { Car left = new Car(cars.get(i++)); Car right = new Car(cars.get(i)); boolean run = true; System.out.println("Run " + runNum + ": " + left.getDriver() + " on " + left.getManufacturer() + " " + left.getModel() + " vs. " + right.getDriver() + " on " + right.getManufacturer() + " " + right.getModel()); Thread.sleep(3000); System.out.println("Ready!"); Thread.sleep(1000); System.out.println("Steady!"); Thread.sleep(1000); System.out.println("GO!"); int seconds = 0; while(run) { System.out.println("Run " + runNum + ": " + left.getDriver() + " on " + left.getManufacturer() + " " + left.getModel() + " vs. " + right.getDriver() + " on " + right.getManufacturer() + " " + right.getModel()); System.out.println(left.getDriver() + ": " + left.getRunDistance() + " meters, " + left.getCurrentSpeed() + " km/h"); System.out.println(right.getDriver() + ": " + right.getRunDistance() + " meters, " + right.getCurrentSpeed() + " km/h"); Thread.sleep(1000); seconds++; if(left.getRunTime() == 0) refresh(left, seconds); if(right.getRunTime() == 0) refresh(right, seconds); if(left.getRunTime() > 0 && right.getRunTime() > 0) run = false; if(left.getRunDistance() >= trackLength && left.getRunTime() == 0) { left.setRunTime(seconds); results.put(cars.size() - results.size(), left); } if(right.getRunDistance() >= trackLength && right.getRunTime() == 0) { right.setRunTime(seconds); results.put(cars.size() - results.size(), right); } } runNum++; } for(Map.Entry<Integer, Car> set : results.entrySet()) System.out.println(set.getValue().getRunTime() + " seconds: " + set.getValue().getDriver() + " on " + set.getValue().getManufacturer() + " " + set.getValue().getModel()); } } 

    2 answers 2

    Correct - this is done using JavaDoc markup)

    Describe the purpose of the class and all public methods, their parameters and return values.

    SetMaxSpeed ​​method non-return maxSpeed ​​values

    This is not entirely correct. The fact that this is a method called setMaxSpeed , we setMaxSpeed see. But what maxSpeed ​​is, nobody knows (as well as the wording "non-return value"). It would be better to have something like:

     /** * УстанавливаСт Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ максимальной скорости. */ 

    And for getMaxSpeed ​​respectively:

     /** * Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ максимальной скорости. * @return Максимальная ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ, Ссли ΠΎΠ½Π° Π·Π°Π΄Π°Π½Π°, Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС -1 */ 

    (There are no such restrictions in your code, I added for clarity)

    The main method to document again makes no sense. All programmers are so well aware that this is the entry point to the program.

    Static method refresh not returning no value with input parameters with if statement

    Also not very useful wording. The fact that this static method can be seen as well, and the fact that it has a conditional operator inside, should not worry us at all (imagine that the method is a black box). It would be more useful to describe the general principle of work in a difficult case. And, of course, the description of the car and time parameters is extremely lacking. What kind of car is it, what time do you need to pass? javadoc should briefly answer these questions. That is, in fact, a programmer who will use this code (for example, in six months) will want to read something in the spirit of:

     /** * ΠžΠ±Π½ΠΎΠ²Π»ΡΠ΅Ρ‚ состояниС ΠΌΠ°ΡˆΠΈΠ½Ρ‹ Π½Π° ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Π²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π». * * ΠŸΡ€ΠΈ расчСтС учитываСтся Π΄Π»ΠΈΠ½Π° трассы ΠΈ максимальная ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ. * @param car ОбновляСмая машина * @param time Π’Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π» ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅Π³ΠΎ состояния */ 

    The main thing: comments must carry really useful information.

      I fully agree with @Nofate , but I’ll add something from myself:

      1) the names of the constants are always in upper case. due to the fact that with the help of the register of letters there is no possibility to separate the logical components of the name (compare: trackLength and TRACKLENGTH), the underscore is used in constants.

       private static final int trackLength = 402; // Π° Π΅Ρ‰Π΅ я Π³Ρ€ΡƒΠΏΠΏΡ‹ констант ΠΎΡ‚Π΄Π΅Π»ΡΡŽ Ρ‚Π°ΠΊΠΈΠΌΠΈ коммСнтариями Π½Π° логичСскиС Π³Ρ€ΡƒΠΏΠΏΡ‹ // ΠΏΡ€ΠΈΠΌΠ΅Ρ€1: константы для автомобиля ... // ΠΏΡ€ΠΈΠΌΠ΅Ρ€2: константы для трассы private static final int TRACK_LENGTH = 402; // максимально-допустимая Π΄Π»ΠΈΠ½Π° Ρ‚Ρ€Π΅ΠΊΠ° 

      ^^ a small line will help a person figure out why this constant is needed

      2) it so happened that all the methods with the 'set' prefix are used to set some properties of the object. it's not typical of java to use it for other methods. Yes, and no semantic load of his name now carries

       private static void setCars() {} // ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π°Π²Ρ‚ΠΎΠΌΠΎΠ±ΠΈΠ»ΠΈ? private static void setUpCars() {} // Π½Π°ΡΡ‚Ρ€ΠΎΠΈΡ‚ΡŒ Π°Π²Ρ‚ΠΎΠΌΠΎΠ±ΠΈΠ»ΠΈ private static void initialize() // инициализация прилоТСния (эта строчка Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ Π² javadoc ΠΊ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρƒ) { // ΠΏΡ€ΠΎΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π°Π²Ρ‚ΠΎΠΌΠΎΠ±ΠΈΠ»ΠΈ initDefaultCars(); // ΠΏΡ€ΠΎΠΈΠ½ΠΈΠ»ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ Π΅Ρ‰Π΅ ... } 

      I consider the last option the most optimal. he gives the maximum amount of information

      3) the main method looks terrible and completely unreadable. methods, in particular, overloaded with functionality should be divided into logical sections. add a comment for each and separate sections with a blank line.

       public class Dragracing { private static Map < Integer, Car > cars = new HashMap < Integer, Car > () ; private static final int TRACK_LENGTH = 402 ; public static void main ( final String[] args ) { // init application setCars () ; // обьявлСниС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… final HashMap < Integer, Car > results = new HashMap < Integer, Car > () ; // здСсь Ρ…Ρ€Π°Π½ΠΈΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ int runNum = 1 ; // Π½ΠΎΠΌΠ΅Ρ€ Π·Π°Π΅Π·Π΄Π° // считаСм Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ Ρ‚Π°ΠΌ для всСх машин for ( int i = 1 ; i < cars.size () ; i++ ) { // для тСста ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Π΄Π²Π΅ сосСдниС? ΠΌΠ°ΡˆΠΈΠ½Ρ‹ final Car right = new Car ( cars.get ( i ) ) ; final Car left = new Car ( cars.get ( i++ ) ) ; // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ учасниках displayRaceStart ( runNum, left, right ) ; // подсчитываСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ Π·Π°Π΅Π·Π΄Π° int seconds = 0 ; boolean run = true ; while ( run ) { // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π΅ состояниС displayRaceStatus ( runNum, left, right ) ; // пишСм для Ρ‡Π΅Π³ΠΎ увиличиваСтся счСтчик seconds++ ; // обновляСм состояниС Π°Π²Ρ‚ΠΎΠΌΠΎΠ±ΠΈΠ»Π΅ΠΉ updateState ( left, seconds ) ; updateState ( right, seconds ) ; // провСряСм условиС остановки сорСвнования? (Π·Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π½Π° Π½ΡƒΠΆΠ½ΠΎΠ΅) if ( (left.getRunTime () > 0) && (right.getRunTime () > 0) ) { run = false ; } // обновляСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ Π³ΠΎΠ½ΠΊΠΈ updateRaceResult ( results, left, seconds ) ; updateRaceResult ( results, right, seconds ) ; } // ΡƒΠ²ΠΈΠ»ΠΈΡ‡ΠΈΠ²Π°Π΅ΠΌ счСтчик ΠΊΡ€ΡƒΠ³ΠΎΠ²? Π·Π°Π΅Π·Π΄ΠΎΠ²? runNum++ ; } // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ Π³ΠΎΠ½ΠΊΠΈ (ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ излишний? Π° Π½Π΅ Ρ„Π°ΠΊΡ‚ Ρ‡Ρ‚ΠΎ Π² Ρ€Π΅Π°Π»ΡŒΠ½ΠΎΠΉ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠ΅ Π±ΡƒΠ΄Π΅Ρ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ 1 строчка послС Π½Π΅Π³ΠΎ) displayRaceResults ( results ) ; } private static void displayRaceResults ( final HashMap < Integer, Car > results ) { for ( final Map.Entry < Integer, Car > set : results.entrySet () ) { System.out.println ( set.getValue ().getRunTime () + " seconds: " + set.getValue ().getDriver () + " on " + set.getValue ().getManufacturer () + " " + set.getValue ().getModel () ) ; } } private static void displayRaceStart ( final int runNum, final Car a, final Car b ) { System.out.println ( "Run " + runNum + ": " + a.getDriver () + " on " + a.getManufacturer () + " " + a.getModel () + " vs. " + b.getDriver () + " on " + b.getManufacturer () + " " + b.getModel () ) ; pause ( 3000 ) ; System.out.println ( "Ready!" ) ; pause ( 1000 ) ; System.out.println ( "Steady!" ) ; pause ( 1000 ) ; System.out.println ( "GO!" ) ; } private static void displayRaceStatus ( final int runNum, final Car left, final Car right ) { System.out.println ( "Run " + runNum + ": " + left.getDriver () + " on " + left.getManufacturer () + " " + left.getModel () + " vs. " + right.getDriver () + " on " + right.getManufacturer () + " " + right.getModel () ) ; System.out.println ( left.getDriver () + ": " + left.getRunDistance () + " meters, " + left.getCurrentSpeed () + " km/h" ) ; System.out.println ( right.getDriver () + ": " + right.getRunDistance () + " meters, " + right.getCurrentSpeed () + " km/h" ) ; pause ( 1000 ) ; } private static void pause ( final long delay ) { try { Thread.sleep ( delay ) ; } catch ( final InterruptedException e ) { // failed sleep - ignore } } private static void refreshCarState ( final Car car, final int time ) { final long maxSpeed = Math.round ( car.getMaxSpeed () / 3.6 ) ; long curSpeed = Math.round ( car.getVelocity () * time ) ; if ( curSpeed > maxSpeed ) { curSpeed = maxSpeed ; } car.setRunDistance ( (car.getRunDistance () + curSpeed) > TRACK_LENGTH ? TRACK_LENGTH : car.getRunDistance () + curSpeed ) ; car.setCurrentSpeed ( Math.round ( curSpeed * 3.6 ) ) ; } private static void setCars () { cars.put ( 1, new Car ( 1, "Toyota", "Celica", 6, 250, "Alex" ) ) ; cars.put ( 2, new Car ( 2, "Dodge", "Viper", 7, 310, "Steve" ) ) ; cars.put ( 3, new Car ( 3, "Porsche", "911", 9, 320, "Martin" ) ) ; cars.put ( 4, new Car ( 4, "Dodge", "Challenger", 9, 250, "Andrew" ) ) ; cars.put ( 5, new Car ( 5, "Toyota", "MR2", 5, 250, "Jim" ) ) ; cars.put ( 6, new Car ( 6, "Honda", "NSX", 8, 280, "Hiroki" ) ) ; cars.put ( 7, new Car ( 7, "Chevrolet", "Camaro", 8, 270, "Ricky" ) ) ; cars.put ( 8, new Car ( 8, "Nissan", "GTR", 8, 310, "Kito" ) ) ; cars.put ( 9, new Car ( 9, "Lamborghini", "Countach", 8, 300, "Linda" ) ) ; cars.put ( 10, new Car ( 10, "VAZ", "2107", 8, 200, "Vasiliy" ) ) ; } private static void updateRaceResult ( final HashMap < Integer, Car > results, final Car car, final int seconds ) { // race results updates when car finishes if ( (TRACK_LENGTH <= car.getRunDistance ()) && (0 == car.getRunTime ()) ) { updateRaceResultImpl ( results, car, seconds ) ; } } private static void updateRaceResultImpl ( final HashMap < Integer, Car > results, final Car car, final int seconds ) { // update car state car.setRunTime ( seconds ) ; // update results results.put ( Integer.valueOf ( cars.size () - results.size () ), car ) ; } private static void updateState ( final Car left, final int seconds ) { if ( left.getRunTime () == 0 ) { refreshCarState ( left, seconds ) ; } } } 
      • > it just so happens that all methods with the 'set' prefix are used for ... I will correct you a little here. This is not just "established", but a very clear concept called JavaBeans, which provides for getters and setters for object properties. - Nofate ♦
      • I did not quite put it correctly, I meant that the limited use of methods with the prefix set in java is a consequence of the fact that you wrote. After all, javabeans / pojo in no way imposes restrictions on the names of other methods (where "other" means any methods except getters / setters - get / set / is) - jmu