Specification

Scenario

The Boyd-Orr Sports Centre has decided that it wishes to encourage the participation of women in sport. To implement this it has decided to designate Wednesday as Ladies’ Day and develop a sports programme designed to be attractive to women. They propose to offer a series of scheduled tutored drop-in fitness classes. Boyd-Orr Sports Centre is receiving a grant from the organisation Healthy West End to cover their costs, but Healthy West End will only continue this grant if they feel that there is adequate participation in the classes. They insist that attendance is monitored every five weeks and, if the overall average attendance over the five weeks is below 12, unpopular classes must be cancelled and replaced with classes that, it is hoped, will be more popular.

An application is required to display the current class schedule and enable the monitoring and replacement to take place.

Data and constraints

The object to be manipulated in the program is a list of Fitness Classes. A Fitness Class has:

  • an ID which is a short String and may be assumed to be unique;
  • a name, which may be assumed to be a one word String (no spaces), e.g. “aerobics”;
  • a tutor’s name which again may be assumed to be a one word String, e.g. “lizzie”;
  • a start time which is an integer representing an hour, e.g. 9 represents 9am;
  • a set of five integers representing attendances for each of five weeks.

You may assume that classes always start on the hour and last for an hour. Currently the earliest class available to Ladies Day participants starts at 09.00 and the latest class starts at 15.00. You can assume that only one class can take place at a time (i.e., start times are unique) and there are no “forbidden” start times, i.e., any hour between 9.00 and 15.00 is a potential start time for a class. This means that the list can contain up to seven Fitness Classes. You should not assume that there will be exactly seven classes offered, and where there are fewer than seven classes, gaps can occur at any time of day. You should allow for the possibility that additional classes may be offered at some later date.

You should assume that there can be more than one class with the same name, and that a tutor may take more than one class.

Program functionality

  • On opening the program the current schedule of classes should be read from a file ClassesIn.txt and the set of attendances for each class should be read from a file AttendancesIn.txt (see Appendix for details of the file formats). It may be assumed that all the data in the files are in the correct format (in addition to the above assumptions, you can also assume that ClassesIn.txt does not contain more than one class starting at a given time). The list of Fitness Classes should be built using this data.
  • A GUI should be displayed showing the current class timetable and having buttons, textfields and labels allowing the user to access the other functions of the application. The timetable should be displayed in a text area. It should show the class name and tutor name for each currently existing Fitness Class underneath a heading representing the start and end time of the Fitness Class (its “timetable slot”). If a particular timetable slot does not have a class allocated to it then there should be some indication that this slot is currently free. Code to display an outline GUI is provided for you – this lays out the basic components, without populating the text area with timetable details. Here is a possible view of the GUI: See image.
  • On clicking the “View Attendances” button, a report should be displayed in a text area in a separate window. The report should display for each class its ID, name, tutor’s name, list of attendances and average attendance. The report should be ordered in descending order of average attendance. Names and figures should be aligned in columns. Non-integer numbers should be formatted to two decimal places. At the bottom of the report the overall average attendance for the entire program of classes should be displayed. A suitable sample report is shown below. See image.
  • Closing the report window should not close the program.
  • On clicking the “Delete” button, the application should look for a class ID number in the appropriate text field of the GUI. A matching Fitness Class in the list should be searched for and if a match is found, the Class should be deleted from the list and the timetable display updated. If no match is found then a warning should be displayed. Deleted classes should not feature in the Attendance Report.
  • On clicking the “Add” button, the application should display a warning message if the list is already full. Otherwise it should look for a class ID, a class name and tutor name in the appropriate text fields of the GUI. If there is already a class with that ID in the list then the application should display a warning and cancel that particular add operation. Otherwise it should create a new Fitness Class with that ID class name and tutor, and set its start time to the earliest available time. The program should check that the class name and tutor fields are non-empty. The set of five attendances for that class should be initialised to 0 (these attendances cannot be changed thereafter). The “timetable” display in the main GUI should be updated. Newly-added classes should also feature in the Attendance Report (and should be included for the purposes of computing the overall average attendance).
  • On clicking the “Save and Exit” button the id, name, tutor name and start time for each Fitness Class should be written to a file ClassesOut.txt. The format of this file is described in Appendix

Program Design

Your program should consist of five classes – these will be provided upon setup (see the Setup section), and some of these are only partially complete.

The class FitnessClass should define a Fitness Class object. It should have a class constant representing the number of weeks over which attendances are recorded (5). Also it should have appropriate instance variables to represent the class ID and name, the tutor’s name, the start time and the set of attendance records.

There should also be:

  • an optional default constructor, and at least one non-default constructor;
  • accessor and mutator (set and get) methods to enable all the instance variables to be accessed and given values;
  • a method to return the average attendance for the class;
  • a method to return a String formatted appropriately for the attendance report;
  • a method to compare two Fitness Class objects appropriately on average attendance.

The class FitnessProgram will maintain a list (implemented as an array) of FitnessClass objects. It should have a class constant representing the maximum number of classes (7) and instance variables to represent the array of FitnessClass objects and the current actual number of (non-null) objects in the list. To implement the full requirements, the methods should include:

  • A default constructor to instantiate the array. Entry X of the array should contain the Fitness Class starting at time 9+X (or null if that time-slot is currently free). There should also be a method to populate the attendance lists for a given Fitness Class in the array, given a String representing a single line of AttendancesIn.txt as a parameter.
  • Appropriate methods to return instance variables including a method to return the FitnessClass object at index X.
  • A method to return the FitnessClass starting at a particular time (or null if no such class exists) and a method to return the first start time that is available for a class.
  • A method to return a FitnessClass object with a given ID number in the array (or null if not present)
  • Methods to insert and delete a FitnessClass object to/from the list.
  • A method to return a list sorted in non-increasing order on the average attendance at each class. You should use the Arrays.sort method.
  • A method to return the overall average attendance.

The class ReportFrame is a JFrame window used to display the report. It will require FitnessProgram and JTextArea objects as instance variables. The methods will be:

  • A constructor with a FitnessProgram parameter used to initialise the FitnessProgram instance variable and add the JTextArea component to the window.
  • A method to build the report for display on the JTextArea

The GUI class SportsCentreGUI will provide the user interface, handle file input, process events and update the display. In particular, it will contain:

  • A constructor which sets up the GUI and calls file input methods.
  • Methods to input the timetable and attendance data from the relevant files.
  • Methods to construct the GUI components
  • Methods to listen for and process events, including adding and deleting a Fitness Class, displaying the report, and saving and closing.
  • A method to update the display after Add and Delete operations.

The class will have as its instance variables suitable buttons, text fields, labels and panels. In addition it will need a FitnessProgram object.

The provided GUI as shown above has a panel at the top (“North”) holding two buttons, a JTextArea in the “Center” and a panel at the bottom (“South”) with a 3×3 grid layout containing labels, textfields and buttons (the buttons have themselves been placed on extra panels so that they retain their correct size).

The class AssEx3 will contain the main method and its purpose will be to instantiate and display a SportsCentreGUI object.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.