Java program using array of objects

Assignment Help JAVA Programming
Reference no: EM132424806

COIT11222 - Programming Fundamentals - Central Queensland University

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.

Assignment Specification
In assignment one we read in multiple customer names, contact phones and parcel weights 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 CourierServiceApp.java is supplied (via the Moodle web site) which supplies the basic functionality of the interface. We are going to store the information in four parallel arrays. The following image is the GUI interface when the CourierServiceApp 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, contact phone and parcel weight are read. Five JButtons are after the parcel weight JTextField which link to blank methods for implementing the functionality of the application.
There is also a JTextArea for displaying the output.

Data structures
For this assignment we are going to store the data of customer names, contact phone, parcel weight and the delivery fee in four parallel arrays. Among four parallel arrays, the data in first three arrays are entered through the corresponding text field while the data in the array of delivery fee is obtained via a method call. The implementation details of the method for calculating the delivery fee - calculateDeliveryFee(int weight) is the same as the method definition in Week5.java of Assignment 1(Just without using the keyword ‘static' in the method header). Do not use the ArrayList data structure.

Declare an array of customer name of String type, the array should hold twenty entries. You can use a constant for the maximum entries allowed.

private String [] customerName = new String[MAX_NUM];

Similarly, you can declare other arrays to represent the contact phone, parcel weight and delivery fee. 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 parallel arrays.

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, contact phone and parcel weight and assign them to the elements of arrays that represent these variables. Then call the method of calculateDelievryFee(int w) to get the value of delivery fee.

The text in the JTextFields is retrieved using the getText() method: customerName[currentCustomer] = nameField.getText(); contactPhone[currentCustomer] = contactPhoneField.getText();
(Note: here we assume customerName[], contactPhone[] and weight[] have been declared as arrays with right type)

When we read the input of parcel weight 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.

weight[currentCustomer] = Integer.parseInt(weightField.getText());

We need to call the method calculateDelievryFee(weight[currentCustomer]) to get the delivery fee, where the array element weight[i] is as the parameter passing to the method. This statement can be written as follows:

fee[currentCustomer]= calculateDeliveryFee(weight[currentCustomer]);

Remember to increment currentCustomer at the end of the enterData () method.
With the sample data entered in last page, the execution result of clicking ‘Enter' button is as follows.

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, contact phone and parcel weigh 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 contact phone and parcel weight fields should also be checked for text and the focus should be returned to the contact phone field and the parcel weight field respectively.

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

2. Display all customer data including delivery fee: displayAll()

When this option is selected, display all of the customer names, contact phones and parcel weights plus the delivery fees which have been calculated so far. At the end of the list display the number of entries, the average parcel weight and the total delivery fee 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 parcel weight in the loop for the average calculation and sum the delivery fee 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 result: 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's delivery request. See the following sample result.

If the search is unsuccessful display an appropriate message and clear the text area.

4. Sort all entries by parcel weight

When the button ‘Sort' is pressed, the data of parcel weight are sorted in ascending order and accordingly the customer names, contact phones and deliver fees are re-listed to reflect this order change, as shown as below. We recommend using the simple soring algorithm-Bubble sort in Chapter 8 of textbook to implement sorting function.

5. 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 (calculateDeliveryFee(int w) 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 and complete report.

Supplied Code
Download, compile and run the supplied code available from the course 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.

Attachment:- JAVA Program using array of objects.rar

Verified Expert

This is a very small Java program of GUI in which we are creating a Courier Service application. In this project, we enter the customer details and the weight of the parcel for delivery and program calculates the delivery charges and display the record for each customer. In this we are using arrays to store the records of each customer and also have the facility to display all the records with total charges collected and average weight of all parcel. We can also sort the records in ascending order on the basis of weight.

Reference no: EM132424806

Questions Cloud

Compare and contrast the presentations of the city : Compare and contrast the presentations of the city of St. Petersburg in A.S.Pushkin's "Bronze Horseman" and N.V. Gogol's "Overcoat."
Describe the reason for the specific evidence rating : For this case study, you will need to visit the National Institute of Justice Programs and Practices website to select a program or practice that is rated.
Compare ten ideas to domino theory : Heinrich summarized what he thought health and safety decision makers should know about accidents. Identify his ten Axioms of Industrial Safety
Define critical issues that police managers have encountered : Discuss the critical issues that police managers have encountered historically and compare them to today's critical issues of immigration, use of force.
Java program using array of objects : JAVA Program using array of objects - develop a Windowed GUI Java Program to demonstrate you can use Java constructs including input/output via a GUI interface
How are the laws reflected in Modern Social Welfare Policy : How are these laws reflected in modern social welfare policy?Identify and describe at least 5 of the underlying values and beliefs that persist to the present
Compare and contrast the human factors theory : Compare and contrast the Human Factors Theory in Practice with the Accident/Incident Theory in Practice.
How strategic management helps your facility control future : As a health care manager, you will be involved in strategic management. Discuss the following in regard to this:
What are some obstacles law-enforcement officers face : One morning, as Burleigh is exiting his vehicle, two young men pull him from his car, point a gun at his head, and tell him to lie on the ground.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Part-2write a program that will perform some of the basic

part-2write a program that will perform some of the basic tasks accomplished by a file integrity checker such as

  Design - uml diagrams and overall design

Develop a problem-based strategy for creating and applying programmed solutions using an object-oriented paradigm - Use an object-oriented development environment in the development, testing and debugging of an object-oriented application.

  Write examples with an code explanations of the oop

Write examples with an code explanations of the OOP (polymorphism, features encapsulation, inheritance and abstraction) with your program code.

  Display a table of values

Using Netbeans, use repetition to display a table of values showing x, the square of x and the cube of x. X is to go up to 5.

  Implement polymorphism and dynamic binding

We are going to implement Polymorphism and dynamic binding by creating generalized methods that accept generalized Employee objects to collect input and display information. However, in the main method we will pass derived objects of the Employee ..

  Practice using recursion with data structures

Write a recursive method in this class called hasSameStructureAs(BinaryTree tree) that returns whether or not a tree has the same structure as another tree.

  Create a guessing game

Create a guessing game where the user enters an integer between 1 and 10.

  Write a recursive function that finds and returns the sum

Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.

  Why is top down design beneficial

This and that is a powerful keyword used in Java. How is it used and why is it so beneficial? Give an example in your explanation.

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date. Throughout the code, comments and/or relevant component names should attempt to make the program understandable.

  Write java program to store employee id number

Use employee data file called employees.txt should comprise at least 5 employee records. Each record stores employee ID number (six digits) last name, first name, middle inital,gender(m or f).

  Understand the principal of remote method invocation

Understand the principal of Remote Method Invocation (RMI) - Understand the benefits and shortcomings of RMI relative to other technologies learned

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