Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Assignment: JAVA Program using array of objects

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.

Assignment Specification

In assignment one we read in multiple customer names, number plates and hours 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 CarParkGUI.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 CarPark 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 four JLabels for the heading and the prompts.

There are three JTextFields in which the customer name, number plate and hour 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.

CarPark class

First step is to create a class called CarPark (CarPark.java) which will not contain a main.

The CarPark class will be very simple which will contain three private instance variables:

o customerName as a String
o numberPlate as a String
o hours 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 calculateParkingFee value returning method*

*You will create a public value returning method calculateParkingFee(), the parking fee can be derived from the instance variable hours. Typically we do not store calculated values in a database so the fee will be derived via your calculateParkingFee () method. Do not store the fee as an instance variable.

CarParkGUI class

Once the CarPark 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 plates and hours in an array of CarPark objects. Do not use the ArrayList data structure.

Declare an array of CarPark objects as an instance variable of CarParkGUI class, the array should hold ten* entries. Use a constant for the maximum entries allowed.

*Ten cars are unrealistic for a carpark but we will use this value during development of this program.

private CarPark [] carParkArray = new CarPark[MAX_CARS];

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

private int currentCar = 0;

CarPark class

First step is to create a class called CarPark (CarPark.java) which will not contain a main.

The CarPark class will be very simple which will contain three private instance variables:

o customerName as a String
o numberPlate as a String
o hours 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 calculateParkingFee value returning method*

*You will create a public value returning method calculateParkingFee(), the parking fee can be derived from the instance variable hours. Typically we do not store calculated values in a database so the fee will be derived via your calculateParkingFee () method. Do not store the fee as an instance variable.

CarParkGUI class

Once the CarPark 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 plates and hours in an array of CarPark objects. Do not use the ArrayList data structure.

Declare an array of CarPark objects as an instance variable of CarParkGUI class, the array should hold ten* entries. Use a constant for the maximum entries allowed.

*Ten cars are unrealistic for a carpark but we will use this value during development of this program.

private CarPark [] carParkArray = new CarPark[MAX_CARS];

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

private int currentCar = 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, number plate and hours and add them to the CarPark array.

The text in the JTextFields is retrieved using the getText() method: String customerName = nameField.getText(); Repeat this to read in the customer's number plate.

When we read the hours 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 hours = Integer.parseInt(hoursField.getText());

We need to add these values customer name, number plate and hours to the array of CarPark 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 Carpark objects. When we create the CarPark object we can pass the customer name, number plate and hours to the object via the parameterised constructor.

carParkArray[currentCar] =
new CarPark(customerName, numberPlate, hours);

Remember to increment currentCar at the end of the enter method.

Next we will output the entry including the customer's parking fee in the JTextArea.

need to create an instance of each of the Carpark objects. When we create the CarPark object we can pass the customer name, number plate and hours to the object via the parameterised constructor.

carParkArray[currentCar] =
new CarPark(customerName, numberPlate, hours);

Remember to increment currentCar at the end of the enter method.

Next we will output the entry including the customer's parking fee in the JTextArea.

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 plate and hours fields should also be checked for text and appropriate error dialogs displayed.

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

2. Display all customers' names, number plates, hours and fees : displayAll()

When this option is selected, display all of the customer names, number plates, hours and fees which have been entered so far. At the end of the list display the average hours of stay and the total of the fees 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 currentCar as the termination value in your loop.

Sum the hours in the loop for the average calculation and sum the fees 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.

3. Search for a customer name: search()

You can just use a simple linear search which will be case insensitive. Use the JOptionPane.showInputDialog() method to input the customer's name.

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

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 (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 (calculateParkingFees 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.

Attachment:- Java-Assignment.rar

Java, Programming

  • Category:- Java
  • Reference No.:- M92799617
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Java

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As