Assessment details COIT 11222
Assessment item 2—JAVA Program using array of objects
Due date: Week 11 T120 – Midnight, Friday (29/5/20)
Refer below for complete assessment item 2 requirements
(Assignment Two) ASSESSMENT
Length: N/A 2
This assessment item relates to the unit learning outcomes as stated in the Unit Profile.
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 unit 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: Pizza.java and RockyWoodfiredPizzasGUI.java, please submit these files as a single zip file. Only include your source code in the zip file you must submit your report separately.
If you submit the source code with an incorrect name you will lose marks.
A report including an UML diagram of your Pizza class (see text p 468 or p 493 8th edition), how long it took to create the whole program, any problems encountered, and screen shots of the output produced with annotations. (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 unit website under Assessment … Assignment 2 Submission.
In assignment one we read in multiple customer names pizza details using both Scanner and GUI dialogs. In this assignment we are going to read in the data and output the information via a GUI interface. The code for the GUI interface called RockyWoodfiredPizzasGUI.java is supplied (via the Moodle web site), this has the basic functionality of the interface and you need to use this for your program. We are also going to store the information in an array of Pizza 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 three JLabels for the heading and the prompts.
There are two JTextFields in which the customer name and number of toppings are entered. There are three JRadioButtons to select a small, medium or large pizza 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.
First step is to create a class called Pizza (Pizza.java) which will not contain a main method.
The Pizza class will be very simple which will contain three private instance variables:
o customerName as a String o pizzaSize as a String
o toppings as an integer
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 calculateCharge value returning method*
*You will create a public value returning method calculateCharge(), the pizza charges can be derived from the instance variables pizzaSize and topping. Typically we do not store calculated values in a database so the charge will be derived via your calculateCharge() method. Do not store the charge as an instance variable.
The method will be like calculateCharge method from assignment one, with the same scale of pricing based on the number of toppings and size of pizza. You can modify and use the code from assignment one or use the code from the published solution of assignment (referenced).
Small base: $6.50
Small toppings: 75 cents ($0.75)
Medium base: $10.50
Medium toppings: $1.25
Large base: $14.50
Large toppings: $1.75
You should use the following method header:
public double calculateCharge()
Note: you do not need to pass pizzaSize and toppings as parameters as you can access the instance variables directly within the class.
Once the Pizza class is implemented and fully tested, we can now start to implement the functionality of the GUI interface.
For this assignment we are going to store the customer names, pizza size and number of toppings in an array of Pizza objects. Do not use the ArrayList data structure.
Declare an array of Pizza objects as an instance variable of RockyWoodfiredPizzasGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed.
private Pizza  pizzaArray = new Pizza[MAX_PIZZAS];
We need another instance variable (integer) to keep track of the number of pizzas being entered and use this for the index into the array of Pizzas objects.
private int currentPizza = 0;
1. Enter button: enter()
For assignment two we are going to use the JTextFields and the JRadioButtons for our input.
When the enter button is pushed the program will transfer to the method: enter() this is where we read the customer name, the pizza size and the number of toppings and add them to the Pizza array.
Only add one pizza when the enter button is pushed, do not have a loop to add them all.
The text in the JTextFields is retrieved using the getText() method:
String customerName = nameField.getText();
When we read the number of toppings input, we are reading a string from the GUI, we will need to convert this to an integer using the Integer wrapper class as per assignment one.
int toppings = Integer.parseInt(toppingsField.getText());
You need to determine which radio button has been selected for the size of pizza, firstly you will notice in the GUI code there has been added a hiddenButton which is not displayed and that it is initially selected: hiddenButton.setSelected(true); You will be able to check if it is selected by: if (hiddenButton.isSelected()) if the hidden button is selected then the user has not selected small, medium or large which they must do, if this is the case then display the following error dialog:
Return the focus to the small radio button: smallButton.requestFocus(); and then exit the method using the return keyword.
If the hidden button is not selected then implement a series of if else statements to determine which of the other buttons have been selected using the isSelected() method as above. Assign the appropriate string to a local String variable e.g. pizzaSize = -Medium-;
Note: in the calculateCharge method in your Pizza class you will be comparing the pizza size to -Small-, -Medium- and -Large- and not -s-, -m- and -l- as in assignment one.
We need to add these values customer name, pizza size and number of toppings to the array of Pizza objects. When we declared our array using the new keyword, only an array of references was created, and we need to create an instance of each of the Pizza objects. When we create the Pizza object we can pass the customer name, pizza size and number of toppings to the object via the parameterised constructor.
pizzaArray[currentPizza] = new Pizza(customerName, pizzaSize, toppings);
Remember to increment currentPizza at the end of the enter method.
Next we will output the entry including the pizza charge 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 the output can be aligned using column widths in the format string.
-Customer Name-, -Size-, -Toppings-, -Charge-));
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(------------ … ----------
Hint: use the format string: -%-30s%-14s%-8d$%5.2f
- to display one pizza order to match the specification.
To retrieve the values from the array use the get and calculateCharge methods in your Pizza class. Create a separate method to display one line of data and pass the index to this method, this is so you will not be repeating the printing code. e.g.
When the data has been entered and displayed, the customer name and number of toppings
JTextFields should be cleared. We can clear the contents by using: nameField.setText(--); and do the same for the toppings field. You will also select the hidden radio button (see above).
The focus should then return to the customer name JTextField.
Data validation (you can implement this after you have got the basic functionality implemented, including checking the radio buttons)
When the maximum number of pizzas is reached, do not attempt to add any more pizzas 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.
Checking the name field:
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 number of toppings field should also be checked for text and appropriate error dialog displayed. The focus should return to toppings field.
We will not worry about checking data types or numeric ranges in this assignment.
2. Display all pizza orders: displayAll()
When this option is selected, display all of the pizza orders which have been entered so far. At the end of the list display the average number of toppings per pizza and the total of the charges collected.
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 currentPizza as the termination value in your loop.
Sum the number of toppings in the loop for the average calculation and sum the charges for displaying at the end, this is the same as assignment one
Return the focus to the name field after display all.
If no entries have been added then clear the text area and display the following error dialog, repeat this for your search.
3. Search for a customer name: search()
First check if a pizza order has been entered (as above).
You can just use a simple linear search which will be case insensitive. Use the JOptionPane.showInputDialog() method to input the customer name.
If the search is successful display the details about the pizza order.
If the search is unsuccessful display an appropriate message and clear the text area, always return the focus to the nameField.
You need to check if a search name has been entered.
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 (within the supplied code).
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.
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), you should try and write a method which accepts an error message as a parameter and displays the error message in a message dialog within the method; use JOptionPane.ERROR_MESSAGE as the last parameter in the message dialog.
Constants must be used for all literal numbers in your code (calculateCharge method and maximum entries).
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 the report and the UML class diagram.
Download, compile and run the supplied code available from the unit 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 T120 COIT11222
The marking scheme is on the following page.
Total number of marks – 25
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 and declared correctly 1
Code in general
Code is indented and aligned correctly and is easy to read (use of vertical whitespace) 1
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 1
No repeated code, printing and error messages 1
Instance variables are correct and private 0.5
Default and parameterised constructors are correct 0.5
Method for calculating the charge is correct 1
Get and set methods are correct 1
Enter pizza order
Customer name is read correctly 0.5
Number of toppings is read correctly and converted to an int 0.75
The correct size is determined from the radio buttons 0.75
Data is added to the object array correctly 0.5
Output matches the specification 0.5
Pizza charge is displayed correctly (two decimal places) 0.5
Error dialog when maximum pizzas is reached 0.5
Error dialog when customer name not entered 0.5
Error dialog when number of toppings is not entered 0.5
Error dialog when size has not been selected 0.5
Focus returned to the relevant field after an error 0.5
Input fields cleared, hidden radio button selected, and focus returned to customer name field 0.5
All records displayed 1.5
Average and total charges are calculated and displayed correctly 1
Output resembles the specification 0.5
Search is correct and correct details returned 1
Empty search dialog checked 0.5
Search is case insensitive 0.5
search key not found is handled correctly 0.5
Exit message displayed 0.5
No pizzas entered is handled correctly (display all and search) 0.5
Correct files submitted including types and names 1
UML class diagram of Pizza class is correct 1
Screen shot(s) of testing and annotations 1
Report presentation and comments including how long it took and any problems encountered 0.5