Coit11222 - programming fundaments - develop a windowed gui


Assessment -JAVA Program using array of objects

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: CarHire.java and CarHireGUI.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 CarHire 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.

Assignment Specification
In assignment one we read in multiple customer names, license numbers and days hired 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 CarHireGUI.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 CarHire objects. The following image is the GUI interface when the CarHireGUI program runs.

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 prompts.
There are three JTextFields in which the customer name, license number and days hired are read. Four JButtons are after the days hired JTextField which link to blank methods for implementing the functionality of the application.
There is also a JTextArea for displaying the output.

CarHire class
First step is to create a class called CarHire (CarHire.java) it will not contain a main method.

The CarHire class will be very simple it will contain three private instance variables:
o customerName as a String
o licenseNumber as a String
o days hired 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 calculateHireRental( ) method*

*You will also create a public value returning method to return the calculated rental. The rental can be derived from the calculation according to the daily rental rates as Assignment 1 (also see below for the daily hire rates). In other words the rental will be retrieved via your calculateHireRental() method, which is a user-defined method inside the CarHire class and it does not contain the keyword static.

2018 XYZ Car Hire Prices
1-3 days: $34.50 per day
From 4 to 7 days: $30.5 per day More than 7 days: $22.5 per day

CarHireGUI class
Once the CarHire 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, license numbers and days hired in an
array of CarHire objects. Do not use the ArrayList data structure.

Declare an array of CarHire objects as an instance variable inside the CarHireGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed.

private CarHire [] carHireArray = new CarHire[MAX_NUM];

We need another instance variable (integer) to keep track of the number of the customer being entered and use this for the index into the array of CarHire objects.

private int currentCustomer = 0;

Button options
1. Enter button: enterData()

For assignment two we are going to use the JTextFields for our input. An entry with sample data in three textFields is shown below.

When the Enter button is pushed the program will transfer to the method: enterData(), this is where we read the customer name, license number and days hired and add them to the CarHire array.

The text in the JTextFields is retrieved using the getText() method: String customerName = nameField.getText(); String licenseNumber = licenseField.getText();
When we read the days hired 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 days = Integer.parseInt(daysField.getText());

We need to add these values of customer name, license number and days hired to the array of CarHire objects, when we declared our array using the new keyword, only an array of references were created, we need to create an instance of each of the CarHire objects. When we create the CarHire object we can pass the customer name, license number and days hired to the object via the parameterised constructor as follows:

carHireArray[currentCustomer] = new
CarHire(customerName,licenseNumber, days);

Remember to increment currentCustomer at the end of the enterData () method.

Alternatively, you can use the setCustomerName( ), setLicenseNumber(), and setDays( ) methods to a CarHire object. Next we will output the entry including the rental in the JTextArea as below when the Enter button is clicked.

To retrieve the values from a CarHire object (as an element of the array - carHireArray), you can use the get and calculateHireRental method in your CarHire class in such a way as:

String customerName=carHireArray[index].getCustomerName(); double rental=carHireArray[index].calculateHireRental();

The supplied code may contain a method for printing the heading and the line underneath. Just like the JTextField the JTextArea has a method setText() to set the text in the text area, note this overwrites the contents of the text area. In addition, the JTextArea also has a method named append() that allows the new generated text being added to the existing text.

When the data has been entered and displayed, the customer name, license number and days hired JTextFields should be cleared. We can clear the contents by using: textField.setText("");
The focus should then return to the customer name JTextField by using:

nameField.requestFocus();

Data validation (you can implement this after you have got the basic functionality implemented)

If one or three textFields has not been entered data and the ‘Enter' button is clicked, your program should pop up a message box to remind user the required input.
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 if there is no text display the following error dialog and use the return statement to exit the method, the focus should return to the name field.

The license number and days hired fields should also be checked for text and the focus should be returned to the license number field and the days hired field respectively.

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

2. Display all customer data including rental: displayAll()

When this option is selected, display all of the customer names, license numbers and days hired plus the rentals which have been calculated so far. At the end of the list display the number of entries, the average days hired and the total rental value. Here it is an example with 3 entries data.

Use a loop structure to iterate through the array, you should be sharing the printing functionality with the Enter button.

Only print the entries which have been entered so far and not the whole array, use your instance variable currentCustomer as the termination value in your loop. You can sum the days hired in the loop for the average calculation and sum the rental value and finally use the append() method of the JTextArea to display them on the text area.

If no entries have been added clear the text area and display the following error dialog, repeat this for your search.

3. Search for a customer's booking: 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 this customer. See the following sample result.

If the search is unsuccessful display an appropriate message and clear the text area.

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 open 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 (calculateHireRental method). Look at the marking criteria to ensure you have completed all of the necessary items

Refer to a Java reference textbook and the course and lecture material (available on the course 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.

Attachment:- Programming Fundaments.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Coit11222 - programming fundaments - develop a windowed gui
Reference No:- TGS02917528

Now Priced at $35 (50% Discount)

Recommended (96%)

Rated (4.8/5)