讲解GUI留学生、辅导Java、讲解Program、Java程序语言调试 调试Matlab程序|辅导Web开发

- 首页 >> 其他
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, 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: 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 incorrect 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.

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 array 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.

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
ogarments as an integer

The following public methods will have to be implemented:
oA default constructor o A parameterised constructor o Two set methods (mutators) o Two get methods (accessors)
ocalculateCharge 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 array of Order objects. Do not use the ArrayList data structure.
Declare an array of order objects as an instance variable of RockyDryCleanersGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed.

private Order [] orderArray = 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 array of Order objects.

private int currentOrder = 0;


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 read the customer name and the number of garments and add them to the Order array. 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 array of Order 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 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.

orderArray[currentOrder] = new Order(customerName, garments);

Remember to increment currentOrder 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("----------- … ----------\n");

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 for you and the values will align with the headings. To retrieve the values from the array 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.
orderArray[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 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 number of garments field should also be checked for text and appropriate error dialog displayed. The focus should return to garments field.

We will not worry about checking data types or numeric ranges in this assignment.

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 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 currentOrder 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 error dialog, repeat this for your search.

3. Search for an order name: search()
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 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.

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), 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 report and the UML class diagram.

Supplied Code

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 T119 COIT11222
The marking scheme is on the following page.

Marking Scheme

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
Order class
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
RockyDryCleanersGUI class
Enter customer name and number of garments
Customer name is read correctly 0.5
Number of garments is read correctly and converted to an int 1
Data is added to the object array correctly 1
Output resembles the specification 1
Order charge is displayed correctly 0.5
Error dialog when maximum orders is reached 0.5
Error dialog when customer name not entered 0.5
Error dialog when number of garments is not entered 0.5
Focus returned to the relevant field after an error 0.5
Input fields cleared and focus returned to customer name field 0.5
Display all
All records displayed 1.5
Average and total charges are calculated and displayed correctly 1
Output resembles the specification 0.5
Search
Search is correct and correct details returned 1.5
Search is case insensitive 0.5
not found is handled correctly 0.5
Exit
Exit message displayed 0.5
General
No orders entered is handled correctly (display all and search) 0.5
Correct files submitted including types and names 1
Report
UML class diagram of Order 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