Question: You are asked to create program that stores running time for all competitors in Gteborgsvarvet (Gothenburg Half Marathon). Create a program according to the following

You are asked to create program that stores running time for all competitors in Gteborgsvarvet (Gothenburg Half Marathon). Create a program according to the following requirements: Competitor class: 1. Create a class with the name Competitor which should have four instance variables: a. name (String) b. age (int) c. gender (String) d. time (Time; a class you need to implement) 2. The constructor of the class should take in all four instance variables: name, age, gender, and time. 3. You should be able to store Competitor objects using Serialization, the Competitor object has a Time object which should also be able to store using Serialization. 4. Youll need to be able to sort the objects based on the running time. You should implement the Comparable interface (comparing two integer values) for this where: =3600+60+ 5. You should Override the toString() to print out the result in the end in following format: H:DD:SS --> Name Hint: String.format() Time Class: 6. Create a class with the name Time. This class should have three instance variables, hours (int), minutes (int) and seconds (int). 7. The constructor of the class should take in all three instance variables: hours, minutes and seconds. 8. Add getter for all instance variables, hours, minutes and seconds. 9. You should be able to store Time objects using Serialization. Main Class: 10. Youll get a text file, participants.txt, including all competitors in the Gteborgsvarvet. The file is structured as name,age,gender, where each competitor has its own line in the file: Gudny,33,Female Kalle,28,Male ... This file should be stored in your project directory:

Sida 6 av 9 2021-11-30 Hgskolan Kristianstad | 044 250 30 00 | www.hkr.se 11. Create a method called letsRun(), taking the path (Path) for the participate.txt file as a parameter: The method should return an ArrayList holding Competitor objects. 12. This method should read each line in the file, generate a random time object and create a competitor object for each participant in the file and store it in an ArrayList. The criteria for the generated random time objects are: hour as an integer value between 1 and 3 minute as an integer value between 0 and 59 second as an integer value between 0 and 59 13. When all competitors are created and stored in the ArrayList, you should sort the ArrayList so the competitor with the shortest running time is listed first and the longest running time last. Hint: Collections.sort() 14. Then, you should print the running time results to the console: Running Result: 1:41:26 --> Gudny 1:50:04 --> Hanna 2:15:16 --> Axel 2:44:22 --> Karitas 2:59:56 --> Stina 3:01:02 --> Kalle 3:45:44 --> John 3:54:38 --> Jonas 15. Finally, use serialization to store the sorted ArrayList to a file with the name RunningTimeResults.ser. This functionality should be implemented in a method called writeToFile() taking the ArrayList with the sorted competitors and the path of RunningTimeResult.ser as a parameters. The program must use at least: Three classes (the main class, Competitor class and Time class) An ArrayList holding the competitor objects. Comparator interface to sort the objects Serializable interface (both in Competitor and Time class) The Main class should have at least three methods; main, letsRun and writeToFile. The Competitor class should have at least constructor and compareTo(). The Time class should constructor and getters for all instance variables.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!