Refer below for complete assessmen.

COIT11222, Assignment Two, 2017 Term Three – Page 1 of 10 Assessment details COIT 11222 Assessment item 2—JAVA Program using array of objects Due date: Week 11 T317 – Midnight, Friday (2/2/18) Refer below for complete assessment item 2 requirements (Assignment Two) ASSESSMENT Weighting: 20% Length: N/A 2 Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed GUI Java Program to demonstrate you can use Java constructs including input/output via a GUI interface, Java primitive and built-in types, Java defined objects, arrays, selection and looping statements and various other Java commands. Your program must produce the correct results. The code for the GUI interface is supplied and is available on the course website, you must write the underlying code to implement the program. The command buttons are linked to appropriate methods in the given code. Please spend a bit of time looking at the given code to familiarise yourself with it and where you have to complete the code. You will need to write comments in the supplied code as well as your own additions. What to submit for this assignment The Java source code: You will need to submit two source files: BodyMassIndex.java and BodyMassIndexGUI.java, please submit these files as a single zip file, do not include your report in the zip file you must submit it as a separate file. o Ass2.zip If you submit the source code with an incorrect name you will lose marks. A report including an UML diagram of your BodyMassIndex class (see text p 493), how long it took to create the whole program, any problems encountered and screen shots of the output produced. (Use Alt-PrtScrn to capture just the application window and you can paste it into your Word document) You should test every possibility in the program. o ReportAss2.docx You will submit your files by the due date using the “Assignment 2” link on the Moodle course website under Assessment … Assignment 2 Submission.COIT11222, Assignment Two, 2017 Term Three – Page 2 of 10 Assignment Specification In assignment one we read in multiple person names, heights and weights using both Scanner and GUI dialogs. In this assignment we are going to read in the data and output information via a GUI interface, the code for the GUI interface BodyMassIndexGUI.java is supplied (via the Moodle web site) which supplies the basic functionality of the interface. We are also going to store the information in an array of BodyMassIndex objects. Look at the code supplied and trace the execution and you will see the buttons are linked to blank methods (stubs) which you will implement the various choices via the buttons. The GUI interface contains four JLabels for the heading and the prompts. There are three JTextFields in which the person, height and weight are entered read. There is also a JTextArea for displaying the output. Four JButtons are at the bottom which link to blank methods for implementing the functionality of the application.COIT11222, Assignment Two, 2017 Term Three – Page 3 of 10 BodyMassIndex class First step is to create a class called BodyMassIndex (BodyMassIndex.java) which will not contain a main. The BodyMassIndex class will be very simple which will contain three private instance variables: o studentName as a String o height as a double o weight as a double The following public methods will have to be implemented: o A default constructor o A parameterised constructor o Three set methods (mutators) o Three get methods (accessors) o deriveBodyMassIndex value returning method* o deriveRatingvalue returning method** *You will create a public value returning method deriveBodyMassIndex(), the body mass index can be derived from the instance variables height and weight. Typically we do not store calculated values in a database so the BMI will be derived via your deriveBodyMassIndex() method. Do not store the body mass index as an instance variable. **You will also create a public value returning method deriveRating() to return the BMI rating “Underweight”, “Normal”, “Overweight” etc (see assignment one). The rating can be derived from the BMI and as with the BMI above typically we do not store calculated values in a database and the rating will be retrieved via your deriveRating() method. Use constants in the if statements for the grade boundaries. Hint: use deriveBodyMassIndex() method above in your deriveRating() method to calculate the BMI (we do not want to repeat any code in our program). BodyMassIndexGUI class Once the BodyMassIndex class is implemented and fully tested we can now start to implement the functionality of the GUI interface. Data structures For this assignment we are going to store the person names, heights and weights in an array of BodyMassIndex objects. Do not use the ArrayList data structure. Declare an array of BodyMassIndex objects as an instance variable of BodyMassIndexGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed. private BodyMassIndex [] bmiArray = new BodyMassIndex[MAX_PERSONS]; We need another instance variable (integer) to keep track of the number of persons being entered and use this for the index into the array of BodyMassIndex objects. private int currentPerson = 0;COIT11222, Assignment Two, 2017 Term Three – Page 4 of 10 Button options 1. Enter button: enterPersonNameHeightAndWeight() For assignment two we are going to use the JTextFields for our input. When the enter button is pushed the program will transfer to the method: enterPersonNameHeightAndWeight() this is where we read the person name, height and weight and add them to the BodyMassIndex array. The text in the JTextFields is retrieved using the getText() method: String personName = nameField.getText(); When we read the height input we are reading a string from the GUI, we will need to convert this to a double using the Double wrapper class as per assignment one. double height = Double.parseDouble(heightField.getText()); Repeat this process to read in the weight value. We need to add these values name, height and weight to the array of BodyMassIndex objects, when we declared our array using the new keyword, only an array of references were created and we need to create an instance of each of the BodyMassIndex objects. When we create the BodyMassIndex object we can pass the name, height and weight to the object via the parameterised constructor.COIT11222, Assignment Two, 2017 Term Three – Page 5 of 10 bmiArray[currentPerson] = new BodyMassIndex(personName, height, weight); Remember to increment currentPerson at the end of the enter method. Next we will output the entry including the person’s BMI and rating in the JTextArea The supplied code contains the methods for printing the heading and the line underneath. The font in the text area is “fixed width” so can be aligned using column widths. displayTextArea.setText(String.format(“%-21s%-9s%-9s%-4s%12s\n”, “Person Name”, “Height”, “Weight”, “BMI”, “Rating”)); Just like the JTextFields the JTextArea has a method setText() to set the text in the text area, note this overwrites the contents of the text area. You can append text to the text area by using the append() method. displayTextArea.append(“———– … ———-\n”); Hint: use the above format string to display all of the values for the person, Java will convert the numerical values to strings for you and the values will align with the headings. To retrieve the values from the array use the get and derive methods in your BodyMassIndex class. Create a separate method to display one line of data and pass the index to this method. e.g bmiArray[index].getPersonName();COIT11222, Assignment Two, 2017 Term Three – Page 6 of 10 When the data has been entered and displayed, the name, height and weight JTextFields should be cleared. We can clear the contents by using: nameField.setText(“”); The focus should then return to the person name JTextField. nameField.requestFocus(); Data valida
tion (you can implement this after you have got the basic functionality implemented) When the maximum number of persons is reached, do not attempt to add any more persons and give the following error message: Use an if statement at the beginning of the method and after displaying the error dialog use the return statement to exit the method. if (nameField.getText().compareTo(“”) == 0) // true when blank Use the above code to check the name field for text and if there is no text then display the following error dialog and use the return statement to exit the method, the focus should return to the name field. The height field should also be checked for text, do the same for the weight. We will not worry about checking data types or numeric ranges in this assignment.COIT11222, Assignment Two, 2017 Term Three – Page 7 of 10 2. Display all persons’ names, heights, weights, BMIs and ratings : displayAll() When this option is selected, display all of the person names, heights, weights, BMIs and ratings which have been entered so far. At the end of the list display the average BMI. . Use a loop structure to iterate through the array, you should be sharing the printing functionality with the enter button, hint: use the method to display a line of data from the enter method. Only print the entries which have been entered so far and not the whole array, use your instance variable currentPerson as the termination value in your loop. Sum the BMIs in the loop for the average calculation at the end. If no entries have been added then clear the text area and display the following error dialog, repeat this for your search.COIT11222, Assignment Two, 2017 Term Three – Page 8 of 10 3. Search for a person name: search() You can just use a simple linear search which will be case insensitive. Use the JOptionPane.showInputDialog() method to input the person’s name. If the search is successful display the details about the person. If the search is unsuccessful display an appropriate message and clear the text area.COIT11222, Assignment Two, 2017 Term Three – Page 9 of 10 4. Exit the application: exit() The exit method is called when the user pushes the exit button or when they select the system close (X at top right hand corner), try and find the code which does this. During a typical exiting process we may want to ask the user if they want to save any files they have opened or if they really want to exit, in this assignment we will just print an exit message. Extra Hints Your program should be well laid out, commented and uses appropriate and consistent names (camel notation) for all variables, methods and objects. Ensure you have header comments in both source files, include name, ID, filename, date and purpose of the class. Make sure you have no repeated code (even writing headings and lines in the output) Constants must be used for all literal numbers in your code (deriveRating method). Look at the marking criteria to ensure you have completed all of the necessary items Refer to a Java reference textbook and the unit and lecture material (available on the unit web site) for further information about the Java programming topics required to complete this assignment. Check output, check code and add all of your comments, complete report and the UML class diagram. Supplied Code Download, compile and run the supplied code available from the course web site. You will see the GUI interface has been implemented and you have to implement the underlying code, use the supplied method stubs and add you own methods. Look for // TODO comments in the code which contain hints. Again no code should be repeated in your program. If you just submit the supplied code you will receive zero marks. Good luck! Bruce McKenzie Unit Coordinator T317 COIT11222COIT11222, Assignment Two, 2017 Term Three – Page 10 of 10 Marking Scheme Marks allocated Total number of marks – 20 Variables, constants and types Variables have meaningful names and use camel notation 0.5 Variables are the correct type and constants are used 0.5 Array of objects is used 0.5 Code in general Code is indented and aligned correctly 0.5 Code is easy to read (use of vertical whitespace) 0.5 Each source file has a header comment which includes name, student ID, date, file name and purpose of the class 0.5 Code is fully commented including all variables and methods 0.5 No repeated code 0.5 BodyMassIndex class Instance variables are correct and private 0.5 Default and parameterised constructors are correct 0.5 Methods for calculating BMI and rating are correct 0.5 Get and set methods are correct 1 BodyMassIndexGUI class Enter person name, height and weight Object array declared correctly 0.5 Person name is read correctly 0.5 Height and weight are read correctly 1 Data is added to the object array correctly 1 Output resembles the specification 1 BMI and rating are calculated correctly 0.5 Error dialog when maximum persons is reached 0.5 Error dialog when person name not entered 0.25 Error dialog when height or weight is not entered 0.25 Input fields cleared and focus returned to person name field 0.5 Display all All records displayed 1 Average is calculated and displayed correctly 0.5 Output resembles the specification 0.5 Search Search is correct and correct details returned 1 Search is case insensitive 0.5 not found is correct 0.5 7 Exit Exit message displayed 0.5 8 General No persons entered is handled correctly (display all and search) 0.5 Correct files submitted including types and names 0.5 9 Report UML class diagram of BodyMassIndex class is correct 1 Screen shot(s) of testing and annotations 0.5 Report presentation and comments including how long it took and any problems encountered 0.5

Leave a Reply

Your email address will not be published. Required fields are marked *