Develop a windowed gui java program

Assignment Help JAVA Programming
Reference no: EM132124076

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

Reference no: EM132124076

Questions Cloud

What is the root cause of lorettas problem : "Loretta marched in here thinking she knows everything. She doesn't want to listen to any of our ideas. It's her way or the highway."
Elvira is an abstract painter with incredible talent : Elvira is an abstract painter with incredible talent but little fame. Is there anything that Elvira can do? Explain.
What kind of response will you focus : What kind of response will you focus on in this course, and how will that type of response develops skills used for academic and professional purposes?
Propose effective digital communication tools : Propose effective digital communication tools to Panasonic to promote its vegetable products.
Develop a windowed gui java program : COIT11222 - Programming Fundaments - Develop a Windowed GUI Java Program to demonstrate you can use Java constructs including input/output via a GUI interface
What is the purpose of nomenclatures : What is the purpose of nomenclatures? What is their role in data infrastructure? Briefly describe nomenclatures and give an example.
Describe some challenges students might face : Introduce the topic of service learning and community partnerships. What are the benefits for students and the community when partnering in service learning.
Probability of a hit : Four balls are independently projected onto one target, the probability of a hit for each is P1 = 0.1 , P2 = 0.2 , P3 = 0.3 , P4 = 0.4.
Experiment with equiprobable outcomes : In an experiment with equiprobable outcomes, the sample space is S = {1,2,3,4} with P(s) = 1/4. A1 = {1,3,4}, A2 = {2,3,4}, A3 = Ø(null set).

Reviews

len2124076

9/27/2018 2:00:55 AM

6 Display all All records displayed 2 Average/total values are calculated and displayed correctly 1 Output resembles the specification 0.5 7 Search Search is correct and correct details returned 2 Search is case insensitive 1 No search result is handled correctly 0.5 8 Exit Exit message displayed 0.5 9 General No customer entered is handled correctly (display all and search) 0.5 Correct files submitted including types and names 0.5 10 Report UML class diagram of CarHire class is correct 1 Screen shot(s) of testing and annotations 0.5 Report presentation and comments including how long it took and any problems encountered 0.5

len2124076

9/27/2018 2:00:46 AM

3 CarHire class Instance variables are correct and private 0.5 Default and parameterised constructors are correct 0.5 Method for calculating rental is correct 1.5 Get and set methods are correct 1.5 4 CarHireGUI class 5 Enter Object array declared correctly 0.5 Customer name is read correctly 0.5 License number is read correctly 0.5 Days hired is read correctly 0.5 Data is added to the object array correctly 1 Output resembles the specification 0.5 Rental is calculated correctly 1 Error dialog when customer name/license not entered 0.5 Error dialog when days hired not entered 0.5 Input fields cleared & focus returned to name/license number/days hired field 0.5

len2124076

9/27/2018 2:00:36 AM

Marking Scheme Marks allocated Total number of marks – 25 1 Variables, constants and types Variables have meaningful names and use camel notation 0.5 Variables are the correct type and constants are used 0.5 Array of objects is used 1 2 Code in general Code is indented and aligned correctly 0.5 Code is easy to read (use of vertical whitespace) 0.5 Each source file has a header comment which includes name, student ID, date, file name and purpose of the class 0.5 Code is fully commented including all variables and methods 0.5 No repeated code 0.5

Write a Review

JAVA Programming Questions & Answers

  Calculate total annual compensation of a salesperson

Develop the program with the reasons each was used. This program was then tested in NetBeans and ran in NetBeans to determine if the program runs correctly after being built.

  Program for a grading system

Must use file operations, exception handling, recursive programming (to calculate averages), and encapsulation (or inheritance) in the program. Program for a grading system to be used by students and professors

  Implement a program that will play the old guessing game

Your assignment is to implement a program that will play the old guessing game "I'm thinking of a number between 1 and 100". The program will be in a webpage

  Support for cloud-based strategies

In this course, you are introduced to general Windows Server concepts like active directory, group policy, security, networking and IIS, access control, and much more. Now that you understand the basic concepts, we will delve a little deeper and l..

  What the code does logically in the program

Compile and run the program. There are ten lines of code marked (1)..(10) that you must explain after analyzing the code, running the program, and examining the output.

  Derive the class extendedroman from the class roman

For part 'a' the source code for class Roman is attached to this assignment. You do not have to include the method decimalToRoman as you modify this class. Also, class Roman is not used in your test program.

  Create a new android application project

You have been hired to create a mobile application for Healthy Life, a local organic bakery and grocery store. The main screen should state the name of the person who owns the phone. Create a new Android Application Project

  Write a program which randomly chooses an integer

Write a program which randomly chooses an integer from 1 to 100. The program should then tell the user.The program should then ask the user to complete the puzzle such that each row and each column consists of the letters

  Write a method void split

Create a project and add DList.java and DListTest.java to it - If you determined the correct answer to Exercise 4.2, you may wonder if the pseudocode

  Application that stores at least four different course names

The application as written does not display certain class names included in the instructions as written.

  Make main method that uses the comparevalues method

Make a main method that uses the compareValues method from question 29 to determine if two integers are the same. Prompt the user for two integers

  Java-s ability to derive new fonts from existing ones

Find out where on your system these font libraries are located. When you do, please specify the operating system and the location (folder/directory) where you found them. Discuss Java's ability to derive new fonts from existing ones.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd