JAVA Program Using Array Of Objects


Assessment  2—JAVA Program using array of objects


Assignment Details

For this assignment, you are required to develop a Menu Driven Console Java Program to demonstrate you can use Java constructs including input/output via GUI dialogs, 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 menu and option selection is supplied: NemoReefToursMenu.java and is available on the unit website, you must write the underlying code to implement the program. The menu selections 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:

o       Booking.java

o       NemoReefTourMenu.java


If you submit the source code with an incorrect name you will lose marks.

A report including an UML class diagram of your Booking class, how long it took to create the whole program, any problems encountered and screen shots of the output produced including annotations. (Use Alt-Prt Scrn 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

You have completed the console program for processing bookings for Nemo Reef Tours. We are going to extend this application so the booking names and number of passengers per booking can be stored in an array of objects, do not use ArrayList.

The program will run via a menu of options, the file NemoReefToursMenu.java has been supplied (via the Moodle web site) which supplies the basic functionality of the menu system.





Look at the code supplied and trace the execution and you will see the menu is linked to blank methods (stubs) which you will implement the various choices in the menu.

Booking class

First step is to create a class called Booking (Booking.java).

The Booking class will be very simple it will contain two private instance variables:

o       Booking Name as a String

o       passengers as an integer

You should also have constants for the charge and discount values.

The following public methods will have to be implemented:

o       A default constructor

A parameterized constructor Two set methods (mutators) o Two get methods (accessors)

A method to calculate and return the charge for the booking. This calculation will be the same as in assignment one. Use constants for all numeric literals.

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.



Note: following basic database principles, calculated values are not usually stored so in this case we will not store the charge as a instance variable, but use the calculate Charge () method when we want to determine the charge.

NemoReefToursMenu class

Once the Booking class is implemented and fully tested we can now start to implement the functionality of the menu system.

Data structures

For this assignment we are going to store the booking names and number of passengers in an array of Booking objects.
Declare an array of Booking objects as an instance variable of NemoReefToursMenu class the array should hold ten bookings.
You will need another instance variable (integer) to keep track of the number of the bookings being entered and use this for the index into the array of Booking objects.


Menu options

1.Enter booking name and number of passengeers: enter Booking  () For assignment two we are going to use the GUI dialog show Input Dialog() for our input. You will need to create the following two dialogs to receive the input from the user. You will not implement

the functionality of the cancel key (need to use exceptions for this). Use Integer.parseInt() to convert the number as a string into an integer.






Data validation (you can implement this after you have got the basic functionality implemented) You will need to validate the user input using a validation loop.

The booking name cannot be blank i.e. not null and the number of passengers cannot be blank and the number of passengers needs to be greater than zero, the same as assignment one.

Output the following error dialogs:



 




When the booking name and number of passengers have been entered successfully into two local variables you will need to add these values into the bookings object array, you will also need to increment a counter to keep track of the number of bookings you have entered and the position in the array of the next booking to be entered.

When the maximum number of bookings is reached do not attempt to add

any more bookings and give the following error message:





When the booking details have been successfully entered, display the details of the booking and the charge on the console screen

Note: For the next three options, display all, statistics and search you should ensure at least one booking has been entered and give an appropriate error message if it there are no bookings entered and for the sorting option you must ensure at least two bookings have been entered, for example:




Display all booking names,number of passengers and charges : displayAllBookings()

When this option is selected display all of the bookings which have been entered so far.




3.   Display statistics: displayStatistics()

When this option is selected you will display the statistics as per assignment one. You can loop through your array of objects to calculate this information.





4.Search for a booking: searchBookings()
You can just use a simple linear search which will be case insensitive. Use the showInputDialog() method to input the booking name (you can share this functionality from enter booking).



If the search is successful display the details about the booking




If the search is unsuccessful display an appropriate message.





5.    Sort the bookings: sortBookings()


This option you will sort the bookings alphabetically (ignore case) by the booking names, you can use any sorting algorithm which you like, do not use any in-built sort methods. Display the sorted list after the sort is complete.




Remember the welcome and exit messages as per assignment one.


To get solution visit our website www.sourceessay.com

Comments

Popular posts from this blog

Assignment Help: Add Valuable Factors In Your Learning Skills

The Helpful Essay Writing Guide: Structure, Outline, Tips And Format

Language Techniques Every Student Must Know