Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

COIT11222, Assignment Two, 2019 Term One - Page 1 of 11 Assessment details COIT 11222 Assessment item 2—JAVA Program using array of objects Due date: Week 11 T119 – Midnight, Friday (31/5/19) Refer...

1 answer below »
COIT11222, Assignment Two, 2019 Term One - Page 1 of 11
Assessment details COIT 11222
Assessment item 2—JAVA Program using a
ay of objects
Due date: Week 11 T119 – Midnight, Friday (31/5/19)
Refer below for complete assessment item 2 requirements
(Assignment Two)
ASSESSMENT
Weighting: 25%
2 Length: N/A

Objectives
This assessment item relates to the unit 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, a
ays, selection and looping statements and various other Java
commands. Your program must produce the co
ect 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: Order.java and RockyDryCleanersGUI.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.
o Ass2.zip
If you submit the source code with an inco
ect name you will lose marks.
A report including an UML diagram of your Order 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.


COIT11222, Assignment Two, 2019 Term One - Page 2 of 11
Assignment Specification
In assignment one we read in multiple customer names and number of garments 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 RockyDryCleanersGUI.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 a
ay of Order 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 garments are entered.
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, 2019 Term One - Page 3 of 11
Order class
First step is to create a class called Order (Order.java) which will not contain a main.
The Order class will be very simple which will contain two private instance variables:
o customerName as a String
o garments as an intege
The following public methods will have to be implemented:
o A default constructor
o A parameterised constructor
o Two set methods (mutators)
o Two get methods (accessors)
o calculateCharge value returning method*
*You will create a public value returning method calculateCharge(), the order charges can be derived
from the instance variable garments. 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 similar to calculateCharge method from assignment one, with the same scale of
pricing based on the number of garments. You can use the code from assignment one.
One to two garments: $8.50 per garment.
Three garments: $20.00.
More than three garments: $20.00 plus $6.50 per garment after that.
You should use the following method header:

public double calculateCharge()
Note: you do not need to pass garments as a parameter as you can access the instance variable
garments directly.
RockyDryCleanersGUI class
Once the Order 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 customer names, number of garments in an a
ay of
Order objects. Do not use the A
ayList data structure.
Declare an a
ay of order objects as an instance variable of RockyDryCleanersGUI class, the a
ay
should hold ten entries. Use a constant for the maximum entries allowed.

private Order [] orderA
ay = new Order[MAX_ORDERS];
We need another instance variable (integer) to keep track of the number of orders being entered and
use this for the index into the a
ay of Order objects.

private int cu
entOrder = 0;


COIT11222, Assignment Two, 2019 Term One - Page 4 of 11
Button options
1. Enter button: enter()
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: enter() this is where we
ead the customer name and the number of garments and add them to the Order a
ay. Only add one
order 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 garments 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 garments = Integer.parseInt(garmentsField.getText());
We need to add these values customer name and number of garments to the a
ay of Order objects.
When we declared our a
ay using the new keyword, only an a
ay of references were created and we


COIT11222, Assignment Two, 2019 Term One - Page 5 of 11
need to create an instance of each of the Order objects. When we create the Order object we can pass
the customer name and number of garments to the object via the parameterised constructor.

orderA
ay[cu
entOrder] =
new Order(customerName, garments);
Remember to increment cu
entOrder at the end of the enter method.
Next we will output the entry including the order 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.

displayTextArea.setText(String.format("%-30s%-17s%-6s\n",
"Customer Name", "Garments", "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("----------- … XXXXXXXXXXn");
Hint: use the above format string to display all of the values for the order except the last placeholder
for the charge (use: $%5.2f), Java will convert the numerical value of number of garments to a string


COIT11222, Assignment Two, 2019 Term One - Page 6 of 11
for you and the values will align with the headings. To retrieve the values from the a
ay use the get
and calculate methods in your Order 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.
orderA
ay[index].getCustomerName();
When the data has been entered and displayed, the customer name and number of garments
JTextFields should be cleared. We can clear the contents by using: nameField.setText("");
The focus should then return to the customer name JTextField.

nameField.requestFocus();
Data validation (you can implement this after you have got the basic functionality implemented)
When the maximum number of orders is reached, do not attempt to add any more orders and give the
following e
or message:


Use an if statement at the beginning of the method and after displaying the e
or dialog use the
eturn 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
e
or dialog and use the return statement to exit the method, the focus should return to the name
field.


The number of garments field should also be checked for text and appropriate e
or dialog displayed.
The focus should return to garments field.
We will not wo
y about checking data types or numeric ranges in this assignment.


COIT11222, Assignment Two, 2019 Term One - Page 7 of 11

2. Display all customer names, number of garments and charges: displayAll()
When this option is selected, display all of the customer names, number of garments and charges
which have been entered so far. At the end of the list display the average number of garments per
order and the total of the charges collected.
.


Use a loop structure to iterate through the a
ay, 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 a
ay, use your instance
variable cu
entOrder as the termination value in your loop.
Sum the number of garments in the loop for the average calculation and sum the charges for
displaying at the end.
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 e
or dialog, repeat
this for your search.


Answered Same Day May 17, 2021 COIT11222 Central Queensland University

Solution

Aditi answered on May 23 2021
143 Votes
Solution/Order.java
Solution/Order.java
public class Order {
    private String customerName;
    private int garments;
    public Order() {
    }
    public Order(String customerName, int garments) {
        this.customerName = customerName;
        this.garments = garments;
    }
    public String getCustomerName() {
        return customerName;
    }
    public int getGarments() {
        return garments;
    }
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }
    public void setGarments(int garments) {
        this.garments = garments;
    }
    
    public double calculateCharge(){
        if(this.garments <= 2)
            return 8.50 * this.garments;
        return 20 + (this.garments - 3) * 6.50;
    }
}
Solution/Report.docx
UML
Details
It took approximately 5 hours to develop the whole program. The major problem encountered while developing the program is to use different dialog boxes for input, to show e
or messages and plain text message. Also, it was a challenge to store all the values in the list and use it for different...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here