Develop a menu driven console java program to demonstrate


JAVA Program using array of objects

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 and is available on the course 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 Car.java
o CarPark.java

Assignment Specification
You have completed the console program for processing cars parked at the Rocky car park. We are going to extend this application so the car's licence plates and hours spent parked can be stored in an array of objects.

The program will run via a menu of options, the file CarPark.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.

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

The Car class will be very simple it will contain two private instance variables:
o licencePlate as a String
o hours as an integer
You can also have constants for the fee values i.e $7.50 and $4.50. 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 A method to calculate and return the fee. This calculation will be the same as in assignment one i.e. First hour is $7.50 and the remaining hours will be $4.50 per hour.

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

CarPark class
Once the Car 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 licence plates and hours in an array of Car objects. Declare an array of Car objects as an instance variable of CarPark class the array should hold twenty cars.
You will need another instance variable (integer) to keep track of the number of the cars being entered and use this for the index into the array of Car objects.

Menu options
1. Enter licence plate and hours parked: enterCar()
For assignment two we are going to use the GUI dialog showInputDialog() 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).

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 licence plate cannot be blank i.e. not null and the hours parked needs to be between one and twelve (1-12) inclusive.
Use the following pseudocode as a guide how to do this.

READ value
WHILE value is incorrect OUTPUT Error message READ value
END WHILE

Output the following error dialogs:

When the licence plate and hours parked has been entered successfully into two local variables you will need to add these values into the Car object array, you will also need to increment a counter to keep track of the number of cars you have entered and the position in the array of the next car to be entered.

When the maximum number of cars is reached do not attempt to add any more cars and give the following error message:

When the car details have been successfully entered display the details of the car and the fee to be charged on the console screen.

Note: For the next three options you should ensure at least one car has been entered and give an appropriate error message if it there are no cars entered, for example:

2. Display all licence plates, hours and fees: displayAllCars()
When this option is selected display all of the cars which have been entered so far.

Review the text p.933for the use of the printf method and using a format string. You could also use String.format() to format your output.

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 car: searchCar()
You can just use a simple linear search which will be case insensitive. Use the showInputDialog() method to input the name (you can share this functionality from enter car).

If the search is successful display the details about the car.

If the search is unsuccessful display an appropriate message.

Remember the welcome and exit messages as per assignment one.

Extra Hints

Your program should be well laid out, commented and uses appropriate and consistent names (camel notation) for all variables, methods and objects.

Make sure you have no repeated code (even writing headings in the output) Constants must be used for all numbers in your code.

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.
Supplied Code

Download, compile and run the supplied code available from the course web site.

You will see the menu interface has been implemented and you have to implement the underlying code, use the supplied method stubs and add you own methods.

Again no code should be repeated in your program.

Attachment:- java assignment.pdf

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Develop a menu driven console java program to demonstrate
Reference No:- TGS01492317

Now Priced at $35 (50% Discount)

Recommended (95%)

Rated (4.7/5)