Introduction
Requirement
MSc / PGDip Information Technology / Software Development
Programming – 2017-18
Assessed Exercise 3
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
1. 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.
2. 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”) with the information lined up in columns. 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:
3. 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.
Closing the report window should not close the program.
4. 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.
5. 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).
6. 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.
Getting started
Launch Eclipse. You should ensure that your workspace is set to H:\workspace\Prog. Use “Switch Workspace->Other” under the File menu to check your workspace location. If you need to change it, note that Eclipse will restart.
Create a new Java project called AE3 in your workspace. You must ensure that in the project creation wizard, you choose the option “use project folder as root for sources and class files”. If you find that folder AE3 has sub-folders src and bin, you have chosen the wrong option and should delete the project and create it again.
From the Programming web page on Moodle, download the zip file from the link “Setup files” for Assessed Exercise 3 under the Section labelled “Assessment”. Extract the files contained in the zip file into your folder H:\Workspace\Prog\AE3. These are:
• FitnessClass.java
• FitnessProgram.java
• ReportFrame.java
• SportsCentreGUI.java
• AssEx3.java
• ClassesIn.txt
• AttendancesIn.txt
Only parts of the corresponding classes have been completed; the remaining code is to be written as part of this exercise. Thus your code should extend the existing template given, utilising the existing classes and methods. New helper methods can be created if desired, but no new classes are required.
The two files ClassesIn.txt and AttendancesIn.txt are two sample input files that can be used for testing purposes.
Program Development
You should design your program incrementally, testing each class and method as it is developed. When you have got a particular stage working make sure that you save a copy of your working file under a different name so that you can revert to an older working version if necessary. Marks will not be given for sections of a program which are coded but do not work. Very few marks will be given for a program that does not compile.
(1) Build the list without any attendance data
Declare the instance variables and class constants for the FitnessClass class. Write methods in that class, as follows:
• a default constructor and a constructor to set instance variables from a String containing data for the ID number, name, tutor name and start time;
• accessor and mutator methods to set and return values of the instance variables, including attendance values.
Declare the instance variables and class constants for the FitnessProgram class. Write a few methods for that class, as follows:
• a default constructor;
• appropriate methods to build the list ordered on start time from data in a file;
• accessor methods to return the number of classes in the list and each individual member of the list.
Before you go any further test that the methods you have written so far work. Write a main method class that opens the file ClassesIn.txt, instantiates and builds a FitnessProgram object and then outputs all the data to System.out using the get methods that you have written in the FitnessProgram and FitnessClass classes.
(2) Format the timetable display in the main GUI JTextArea
The timetable display is the hardest part of this section. To simplify the task of creating the display, deal with each line separately. You may need to write some more methods in the FitnessProgram class to help you. A potentially useful addition might be:
• a method that takes an integer parameter t representing a start time and returns the FitnessClass with start time t, or null if there is no such class.
(3) Add in the attendances
Attendances should be initialised automatically as the GUI is being built. A line of the attendances file AttendancesIn.txt should contain an ID number, and five integers representing attendances for each of the five weeks being monitored. The program can assume that the ID number will match an existing class. You will need to write a method in the FitnessProgram class to search the list on FitnessClass ID.
Before moving on, test that you have successfully set the attendance values either using the debugger or using System.out statements.
(4) Display the Attendance report
You will have to write methods that enable you to sort the class list on average attendance using the Arrays.sort method. Then you can write the ReportFrame. class and the event handler that displays the attendance report when the “View Attendances” button is clicked. Closing a ReportFrame. should NOT end the program.
(5) Write the Add and Delete button event handlers
• The Add button event handler should add a Fitness Class using data from all text fields. As specified if there is no available start time or the ID duplicates an existing one then a warning should be displayed.
• The Delete button event handler should take data only from the ID field. If there is no such Fitness Class a warning should be displayed.
(6) Write the Save and Close button event handler
This event handler should generate a text file in a format similar to ClassesIn.txt (note that the classes need not be ordered on start time) and then close the program.
Report
Write a short summary (no more than one page, excluding screen dumps) of the final state of your program in a Word file. It should indicate how closely your program matches the specification. There should be a statement detailing the inputs that you have used to test that the program is working correctly before submitting the final version. This statement should include a description of the results you would expect when executing the program with your data. The report should include:
• Your name and student number at the top.
• Any assumptions you have made that have affected your implementation.
• Any known deficiencies, e.g., missing functionality or discrepancies between your expected and actual results and how you might correct them. If your program does meet the specification, all that is needed is ONE sentence stating this.
• Details of any test data used and the results expected and obtained should be provided.
• Screenshots of your main GUI display and the attendances report that result from the test data you used.
Submission
All submission for this exercise is to be done electronically – no hard-copy submissions are required. You need to submit a zip file containing the following:
• Your report on the program, with screenshots, contained in AE3report.doc or AE3report.docx
• Your Java source files:
o AssEx3.java
o FitnessClass.java
o FitnessProgram.java
o ReportFrame.java
o SportsCentreGUI.java
To create the zip file, select the above files (either by choosing them from within your AE3 folder, or by selecting all files from within another folder where they are the only files present). Note that, to select multiple files, hold down the Control key whilst left-clicking on the file icons. Then right-click on one of the highlighted files and choose “7-Zip -> Add to archive”. From the wizard, choose “zip” as the archive format and ensure that the filename is AE3.zip. (e.g., AE3_SmithJane.zip). You should find that AE3.zip has now been created. You can double-click on this file to check its contents.
On the Programming Moodle page (), you will find under the Section labelled “Assessment” a small submission box icon labelled “Assessed Exercise 3”. Click on the link. Follow the on-screen instructions to upload your zip file AE3_.zip.
You can submit versions as many times as you like prior to the deadline. As a result it would be sensible to try out the submission mechanism with early versions of your code well before the deadline just to ensure that you are familiar with the process, to avoid any last-minute panic.
Notes:
• Do NOT alter the files in Workspace\Prog\AE3 after the deadline, so that if there is a problem with the zip file then you can resubmit your files, and their date of last modification will still be prior to the deadline.
• If any print statements have been included for debugging purposes, please remember to comment them out before submission.
Techniques
The code constituting your solution to this exercise should involve only techniques that have been covered in the Programming course. That is, classes or methods that have not been covered in the course should not be used.
Marking Scheme
The assignment will be marked in bands on the scale A1,A2,………..F3,G1,G2,H. Marks will be awarded according to the quality of three separate elements:
Element Weighting Contents
Functionality 50% Proportion of the specified functionality implemented, and program correctness
Design 25% Choice of methods and instance variables within classes, design of methods
Documentation and Testing 25% Readability of code (comments, layout, indentation), quality of status report, selection of test data
Notes:
• We are expecting you to stick rigidly to the specification. Don’t spend time implementing functionality that was not asked for – it will not receive additional credit and your time would be better spent on other tasks!
• If major aspects of the functionality are not even attempted then the credit given for the Design, Documentation and Testing will be reduced. So for example if only half of the functionality is attempted then it will only be possible to obtain half marks for Design, Documentation and Testing.
Bands will awarded according to the following broad criteria:
A1,A2,A3,A4,A5 Excellent in all three elements. At the A5 level there may be minor errors in several elements
B1,B2,B3 Very Good. Possibly not all functionality implemented but the design and documentation of what was done was very good
C1,C2,C3 Good Definitely of MSc standard but too many errors to attract a B level band. A fully functional program with poor design and documentation would only attract a C level band
D1,D2,D3 Satisfactory Diploma standard. Maybe some major aspect of functionality missing and weak design or documentation
E1,E2,E3 Weak Some functionality but not much
F1….G2 Poor Very little done
H Nothing submitted
Appendix – format of the input/output files
The file ClassesIn.txt should consist of records of FitnessClass data, one record per line. The line should contain the class id, the class name, the tutor name and the start time separated by spaces. A suitable sample file is shown below:
mp2 pilates mandy 14
ls1 step linda 15
mp1 pilates mandy 11
jy1 yoga jane 9
lb1 badminton liz 10
The file AttendancesIn.txt should contain lines of attendance records. Each line should contain the ID of a class followed by the set of five attendance figures, also separated by spaces. A suitable sample file is shown below:
jy1 10 10 10 10 10
mp1 6 5 6 7 5
ls1 9 7 12 14 15
mp2 10 12 15 15 14
lb1 12 12 12 12 12
Note that neither file is in any particular order!
The file ClassesOut.txt should consist of records of FitnessClass data, in the same format as ClassesIn.txt (but the records need not be in any particular order). Obviously the actual data will depend on the classes that have been deleted / added during the program run.
It may be assumed that all the data in the input files are in the correct format, so no validation of the input files is required as part of this exercise.