Highlights
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 booking name and number of passengers 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.
Booking class
First step is to create a class called Booking (Booking.java) which will not contain a main.
The Booking class will be very simple which will contain two private instance variables:
o bookingName as a String o passengers as an integer
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 tour charges can be derived from the instance variable passengers. 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 discounts based on the number of passengers.
Charge per person $85.50.
One to two passengers: no discount. From three to five passengers: 10% discount. From six to ten passengers: 15% discount. More than ten passengers: 20% discount.
You should use the following method header:
public double calculateCharge()
Note: you do not need to pass passengers as a parameter as you can access the instance variable passengers directly.
NemoReefToursGUI class Once the Booking 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 booking names, number of passengersin an array of Booking objects. Do not use the ArrayList data structure. Declare an array of Booking objects as an instance variable of NemoReefToursGUI class, the array should hold ten entries. Use a constant for the maximum entries allowed.
private Booking [] bookingArray = new booking[MAX_BOOKINGS];
We need another instance variable (integer) to keep track of the number of bookings being entered and use this for the index into the array of Booking objects.
private int currentBooking = 0;
Button options
When the enter button is pushed the program will transfer to the the method: enter() this is where we read the booking name and the number of passengers and add them to the Booking array.
The text in the JTextFields is retrieved using the getText() method:
String bookingName = nameField.getText();
When we read the number of passengers 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 passengers = Integer.parseInt(passengersField.getText());
We need to add these values booking name and number of passengers to the array of Booking 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 Booking objects. When we create the Booking object we can pass the booking name and number of passengers to the object via the parameterised constructor.
bookingArray[currentBooking] = new Booking(bookingName, passengers);
Remember to increment currentBooking at the end of the enter method.
Next we will output the entry including the tour 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 can be aligned using column widths.
displayTextArea.setText(String.format("%-30s%-17s%-6s\n", "Booking Name", "Passengers", "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 booking except the last placeholder for the charge (use: $%5.2f), Java will convert the numerical value of number of passengers 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 Booking class. Create a separate method to display one line of data and pass the index to this method. e.g. bookingArray[index].getBookingName();
When the data has been entered and displayed, the booking name and number of passengers JTextFields should be cleared. We can clear the contents by using: nameField.setText("");
The focus should then return to the booking name JTextField.
nameField.requestFocus();
Data validation (you can implement this after you have got the basic functionality implemented)
When the maximum number of bookings is reached, do not attempt to add any more bookings 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 passengers field should also be checked for text and appropriate error dialog displayed. The focus should return to that field.
We will not worry about checking data types or numeric ranges in this assignment.
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 currentBooking as the termination value in your loop.
Sum the number of passengers in the loop for the average calculation and sum the charges for displaying 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.
If the search is unsuccessful display an appropriate message and clear the text area, always return the focus to the nameField.
If the search is unsuccessful display an appropriate message and clear the text area, always return the focus to the nameField.
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.
This COIT 11222: JAVA Assignment has been solved by our JAVA experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.