Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are asked to create program that stores running time for all competitors in G oteborgsvarvet (Gothenburg Half Marathon). Create the program according to the

image text in transcribed
image text in transcribed
You are asked to create program that stores running time for all competitors in G oteborgsvarvet (Gothenburg Half Marathon).
Create the 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:
Stotal =h3600+m60+s
5. You should Override the toString() to print out the result in the end in following format:
Hint: String.format()
Time class:
H : MM : SS > Name
1. Create a class with the name Time. This class should have three instance variables, hours (int), minutes (int) and seconds (int).
2. The constructor of the class should take in all three instance variables: hours, minutes and seconds.
3. Add getter and setter for all instance variables.
4. You should be able to store Time objects using Serialization.
Main class:
1. Youll get a text file, participants.txt, including all competitors in the G oteborgsvarvet. The file is structured as name,age,gender, where each competitor has its own line in the file:
Rickard,37,Male Anna,28,Female ...
This file should be stored in your project directory.
2. Create a method called letsRun(), taking the path (Path) for the participate.txt file as a param- eter: The method should return an ArrayList holding Competitor objects.
3. 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 critera for the generated time objects are:
hours 2 [1, 3] minutes 2 [0, 59] seconds 2 [0, 59] 8{h,m,s} 2 Z
4. hen 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.hen 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()
5. Then, you should print the running time results to the console:
Figure 8: Running results printed.
6. Finally, use serialization to store the sorted ArrayList to a file with the name RunningTimeRe- sults.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.
1.2 Thsk 2 Yoe are usked to create program that stores funning time for all coanpetitorn in Gtelongyarvet (Gothenburg Half Marathon). Croate the progrum accerating fo the fallowing reguiremients: Competitor classi 1. Create a clas with the satme Cotmpetitor which should have four instance varablos: (a) natuo (String) (b) age (int) (c) Fender (String) (d) then (Time: a elaes you tood to impleanent) 2. The oonstructor of the elas mbadk take in all fone instance variables: natos, age, gender, and time. 3. You shoeld be able to store Competitor objects uning Serialization, the Compritor objet han a Time object which shotld also be abbe to store using Serielization. 4. Yon'7l need to be able to sort the objects based on the ruaning time, You should inplanent the Comparable interface (comparing two integer values) for this where: Slatal=h3000+m60+n 5. You should Overide the toString() to print out the rexult in the end in followitug format: "H:MM=SS>Name Wist. String. formet (?) Tme class: 1. Create a class with the name Tiew. Thie class should have three instance variables, bours (int), minatas (iat) and acconds (int). 2. The conatractor of the class should take in all three inatance variables hourn, misates and acronds. 3. Nud getter and setter for all inatance variables. 4. You nhould the able to ntore Time objects tusiag Serialisation. Main cluess: 1. You ll got a text file, participanta.txt, inchuding all conapetitors in the Gooteboerovarvet. The file ia structared as "natioe, age synaler", where earlu competitos has its own line in the file Rickourd.37, Made Ansa,28, Feenale The file should be staroxl in your project directary. 2. Create a method callod letsRua(), taking the path (Path) for the participate.txt file as a parameter: The method should return an ArrayList holding Competitor objects. 3. This tnethod 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 critera for the generated time objects are hours[1,3]minutes[0,59]seconds[0,59]{h,m,s}Z 4. hen all competitors are ereated 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.hen all competitors are created and stored in the ArrayList, you should sort the ArrayList so the competitor with the shortest running time is listod first and the longest running time last, Hint: Collections,sart() 5. Then, you should print the running time results to the console: Figure 8: Running results printed. 6. Finally, twe merialization to store the norted ArrayLivt to a file with the name Running TimeResulteser. This functionality should be implemented in a method called writeToFile() taking the ArrayList with the sorted competitors and the path of "Running TimeResult ser" as a parameters. The program must use at least: - Three classes (the main clas, Competitor class and Time class) - An ArrayList houling 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 shoukd constructor and getters for all instance variables

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

Do you think physicians should have unions? Why or why not?

Answered: 1 week ago