COMPSCI 4039 PROGRAMMING IT

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

PROGRAMMING IT

(COMPSCI 4039)

Wednesday 15th December 2021

1. Every year Javaville holds an annual sporting competition. One of the events that you have been placed in charge of is the running event. The aim of the event is to have the fastest average lap time. Each runner that participates in the event will run twice, with their average lap time being used to determine their position in the running event leader-board.

You are to create a software program that will be responsible for reading in a text file that contains the recorded lap times and a note of any concessions or disqualifications. A concession indicates the number of seconds that should be deducted only from the recorded first lap time of an athlete. A disqualification indicates that an athlete should not appear on the leaderboard.

You are to create a leaderboard, that will display the athletes first name, last name, first and second lap times along with their their calculated average lap times as shown below.  Those with the fastest average lap times are shown at the top, with the slower average times at the bottom. Any concessions that were made should be noted on the row of the athlete. Those that are flagged for disqualification should not be included in the leaderboard, but be printed at the bottom, indicating they have been disqualified. The leaderboard should first be printed to the console,before being illustrated on a GUI window.

Pos   |     Firstname   |        LastName   |     Lap1   |      Lap2   |       Avg

1   |         Charley   |              Black   |   02:54   |   03:59   |   03:26   :  -39 . 0s

2   |             Anita   |               Case   |   03:12   |   04:14   |   03:43   :  -47 . 0s

3   |           Debbie   |            Morgan   |   03:49   |    03:51   |   03:50

4   |               Greg   |       Stanford   |   03:58   |   03:50   |   03:54

5   |             Randy   |       Piccardo   |   04:40   |   03:20   |   04:00

6   |           Calumn   |       Mashford   |    05:01   |   03:29   |    04:15

7   |            Arnold   |             Smith   |   03:42   |   04:56   |   04:19   :  -52 . 0s

8   |           George   |          Stanley   |   03:58   |   04:51   |   04:24

--Disqualifications--

Ashley  Morgan       Disqualified

Tim  McGregor       Disqualified

You have been provided some starter code files that will be used to create this project. You have also been provided the data needed for this project in the ’times.txt’ file. Each row in this file corresponds to an athlete. Two example rows are as follows:

”Arnold Smith,04:34 04:56,concession-52s” ”Ashley Morgan,04:19 04:32,disqualified”

This first line indicates the athlete first name is ”Arnold”, their surname is ”Smith”, their first lap time is 4 minutes 34 seconds (stored as MM:SS format) and their second lap time is 4 minutes 56 seconds (again stored as MM:SS). The ”concession-52s” indicates their first lap time is to be decreased by 52 seconds.

The ”disqualified” on the second line indicates that the athlete ”Ashley Morgan” should be disqualified and therefore not appear on the leaderboard, but be printed at the bottom under ”disqualifications” .

The following code snippet (which can be found in the provided Athlete.java file) will be used to represent the athletes.

public c l a s s Athl e t e   {

private String   fir st N am e ;

private String   surname ;

private   double fir s t Tim e ;

private   double second Time ;

private double average Time ;

}

In this code, firstName and surname identify the runner. firstTime, secondTime and averageTime are doubles that store the times recorded for their first lap, second lap and the calculated average lap.

(a) Create a constructor for this class. It should take 4 parameters, two Strings for firstname/sur- name and two doubles for first/second lap time. Create a helper method to calculate the  average lap times and set it in the constructor.       [2]

(b) Write an appropriate accessor and mutator for the first lap and second lap attributes in the class.               [2]

(c) The runners for the event held at Javaville need to be stored on a leaderboard. In order to

facilitate this, each Athlete object needs to be compared to another as follows:

• If A has a quicker average time compared to B then A should come before B.

•  If A and B have the same average time, then if the surname of A comes before B lexicographically, A should come before B.

•  If A and B have the same average time and surname, then if the firstname of A comes before B lexicographically, A should come before B.

• Otherwise B comes before A.

Make the Athlete class implement a generic Comparable interface that will expect an Athlete type. Implement the method to compare two Athlete objects according to the above criteria and return a suitable integer value for comparison.  [6]

(d) We now require a Table class to store a list of all the athletes. Part of the class is provided as follows in the ”Table.java” file:

public   class Table   {

private Arr ay Li st  runn er s ;

private String   he ader   =

String . form at ( ”%3s    |   %10 s    |   %10 s    |   %5s    |   %5s    |   %5s ” ,

” Pos ” ,   ” Fir st n am e ” ,   ” LastName ” ,   ” Lap1 ” ,   ” Lap2 ” ,   ”Avg ” ) ;

}

The runners data structure will be used to store all the athletes that are competing in the competition. The header String will be used when creating the table output to display the rankings of the runners on the leaderboard.

Create a constructor for the Table class. The constructor should not take any input paramet- ers. Also create a method that will take an Athlete object as input parameter, and add it to  the runners data structure.   [3]

(e) The following starter code is provided in the ”Note.java” file:

public clasNote   {

protected String   message ;

}

The class has a String attribute which contains a message. Expand this class by creating a constructor to set this message, and create a getter for the message attribute.   [2]

(f) Expand the Conduct class that should inherit from the Note class.  The Conduct class should call the super constructor passing in an explicit String  : disqualified to indicate that a disqualification as occurred.   [2]

(g) Expand the Concession class that should inherit from the Note class. The Concession class should take one input parameter that is a double and be set to an appropriate attribute. Call the super class with an explicit String ”-” concatenated with the input parameter to indicate a concession was granted.   [3]

2.     (a) Update the Table class and create a data structure to hold those Athletes that have been disqualified from the event. Create an appropriate method within the class body to take an Athlete object and add it to the data structure.      [2]

(b) The lap times for a given run are stored in MM:SS format, for example, 03:31 indicates a time of 3 minutes 31 seconds. The Athlete class stores lap times as a double, representing seconds. This should be converted to MM:SS format when printing. A Conversion class with two static methods as below is provided in the ”Conversion.java” file:

public   class Conver sion   {

public   static   double convert Time To Second s ( String   time )   {

// Add code here

}

public   statiString   convert Second s To Time ( double time )   {

// Add code here

}

}

Expand on this code and create appropriate methods to return either a double, or String representation.   [4]

(c) Update the Athlete class by adding a method to take a Note object and assign it to an instance variable.

In the main method in the provided ”Main.java” file you are to first instantiate the Table class as an object. For each line in ’times.txt’ create an Athlete object. The information you pass to the constructor will depend on whether there is a concession or not.

If there is a concession, you should update the 1st lap time by subtracting the concession time, before passing the input parameters to the Athlete object constructor.  Create a Concession object and pass it to the Athlete object.

If there is a disqualification, create a Conduct object and pass it to the Athlete object. In this instance, the Athlete object should be added to the disqualified data structure. Otherwise, they should be added to the runners data structure.    [8]

(d) Create a toString() method in the Athlete class that will represent the object in text form. The method must return a String, formatted in a manner that aligns with the header String  provided in the Table class example. The Athlete object will only return the last 5 pieces of information (out of the 6) that are required by the header String. In the event the Athlete object has a Note object (i.e. their Note attribute is not null), the message from that Note object should be concatenated to the output String. For example, if they have a Concession object, the time they were awarded should be added to the toString() output. If they have a Conduct object, then their disqualification message should be appended to their toString() output. [4]

(e) Create a toString() within the Table class. This method will be responsible for sorting the runners data structure. Implement the necessary logic to sort the collection according to the sorting criteria. After sorting the collection, iterate over each Athlete object within the collection. On each iteration, create a String that will contain all the necessary information provided by the header String. Each iteration will involve you creating a ’row’ for the leaderboard. You will want to leverage on the indice value, newline characters and the toString method from the Athlete class to achieve this. Afterwards, concatenate a header indicating the disqualified athletes and print out those athletes from the disqualified data structure. [6]

(f) Call the toString() method from the main method and print the result to the console. The result of this method call should look similar to the example at the top of this document. [4]

3.     (a) Boilerplate code for the GUI application has been provided in ”GUI.java”, the code is not listed here for brevity.  The code provides a basic implementation of a JFrame with some JPanel components. Expand on this class by creating another JPanel object. Add a JTextArea component to this newly created JPanel object and add the JPanel object to the centerPanel object. Set the title of the JFrame to be ”GUI Table” [5]

(b) Expand on the two provided methods in the GUI class. In setRow(), update the method to take a String input parameter and display it on the JTextArea. In the showGUI() method, you want to add code to display the JFrame object. In addition, ensure that users cannot type and modify the results when the GUI is displayed.

Expand on the main method. Create a GUI object. Then iterate through the rows of the leaderboard and pass each row to the GUI. Utilise the provided methods in the GUI class to take the String parameters and display them on the GUI.   [7]



发表评论

电子邮件地址不会被公开。 必填项已用*标注