Objectives:
This assessment item is designed to test your understanding of topics such as array/ArrayLists, methods with parameters, sorting, searching and input validation.
Assessment Task:
Write a java application that allows the user to input and validate Order details of online grocery orders for N customers. The N should be set as a constant (final) in your application and use a random number generator to randomly create a value between 6 and 9. The application should also allow the user to search for Customers belonging to the same suburb, sort customers based on their purchase amount. The purchase amount should be between 60 and 500. The postcode, purchase amount, and Total payable must be stored in 3 single dimensional Arrays or an ArrayList.
Your application should display and execute a menu with the following options. A switch statement must be used to execute the following menu options.
- Read, validate, and store postcode, and purchase amount for N customers.
- Calculate, store and display the total payable for all customers.
- Display postcode and total payable for purchase amounts of $400 and above.
- Find and display the postcode/s with the highest purchase amount.
- Find and display the postcode/s with the lowest purchase amount.
- Sort and display the total payable in descending order.
7 Search and display all purchase amount and Total payable with a given postcode.
- Exit from the application.
- Read, validate, and store postcode and purchase amount for N customers.
This option reads postcode and purchase amount for all customers from the keyboard and stores them in two separate single dimension Arrays/ArrayLists. While the postcode is less than 4121 or greater than 4123 then an appropriate message should be displayed and the user should be given chance to enter a correct postcode. Similarly while the purchase amount is less than $60 or greater than $500 then an appropriate message should be displayed and the user should be given the chance to enter a correct purchase amount.
- Calculate, store and display the total payable for all customers
This option calculates the total payable applying the delivery charges to the purchase amount. There is free delivery for purchases of $400 and above from postcode 4121. The delivery charges for all suburbs are given below.
The delivery charges are as shown below in Table 1 given on next page.
Table 1: Delivery Charges
Postcode
|
Applicable Delivery Charge
|
4121
|
$8
|
4122
|
$12
|
4123
|
$15
|
- Display postcode and total payable for purchase amounts of $400 and above.
This option displays the postcodes and total payable for all purchases of $400 and above. If there are no purchases to be displayed an appropriate error message should be displayed.
Example:
Postcode
|
Total Payable
|
4121
|
$423.23
|
4122
|
$415.50
|
4122
|
$456.75
|
4125
|
$512.00
|
- Find and display the postcode/s with the highest purchase amount.
This option displays the postcode/s with the highest purchase amount as shown in the example below.
Example:
Postcode
|
Purchase Amount
|
4124
|
$497.00
|
4125
|
$497.00
|
- Find and display the postcode/s with the lowest purchase amount.
This option displays the postcodes with the lowest purchase amount as shown in the example below.
Example:
Postcode
|
Purchase Amount
|
4121
|
$62.00
|
4123
|
$62.00
|
- Sort and display the total payable in descending order.
This option sorts and displays the total payable stored in Array/ArrayList for all customers in descending order. You can use any sorting algorithm. A built-in sort algorithm for sorting is not allowed in this assignment.
Example:
Postcode
|
Purchase Amount
|
Total Payable
|
4125
|
$497.00
|
$512
|
4124
|
$497.00
|
$511
|
4122
|
$444.75
|
$456.75
|
4121
|
$423.23
|
$423.23
|
4122
|
$403.50
|
$415.50
|
4123
|
$62.00
|
$75.00
|
4121
|
$62.00
|
$70.00
|
- Search and display all purchase amount and total payable with a given postcode.
This option searches Array/ArrayList and displays the purchases which have postcode equal to the given postcode. The application asks the user to enter the postcode using the keyboard and searches for it. If the postcode entered from the keyboard is found then the application displays postcode, purchase amount and total payable otherwise it displays an appropriate message. If there are more than one entry with the given postcode all the entries should be displayed. A built-in search algorithm for searching can be used in this assignment.
- Exit from the application.
The application should display the message “Thank you for using this application” and your student id number and then exit from the application. The application should be user-friendly by displaying appropriate welcome and exit messages. The following classes and methods could be used.
The application should work in a loop to enable the user to read, validate and store postcode and purchase amount for N customers, and execute all other options.
Program Design:
You may use any design that meets the specification. However, a good design will adhere to the following guidelines:
Be logically correct
Be easy to read and maintain
Be well-desinged
Use a UML class diagrams and activity diagrams
Use appropriate classes, methods and fiels
Your design can follow the guidelines for classes and methods as listed below.
public class Purchase
{
//fields
// default and parameterised constructors
//get and set methods
//display method
//Method to display postcode, and total payable for purchase amounts of $400 and above
//Method to find and display the postcode/s with the highest purchase amount
//Method to find and display the postcode/s with the lowest purchase amount
//Method to sort and display the total payable in descending order
//Method to search and display all purchase amounts and total payables with a given postcode
}
public class PurchaseTest
{
//Arrays/ArrayList
// declare N as a constant.
// initialise N to a random number in the range 6 to 9.
//constructors
//Method to read, validate and store postcode and purchase amount for N customers
//Method to display the total payable for all customers
//main method
public static void main(String[] args)
{
// create object of type Purchase
// While loop to continually display menu and read option
// Switch statement within while to invoke method corresponding to each option.
}
}
You may add/use other methods, parameters, fields/variables, constants, etc. which you need to complete the application.
Testing:
Testing is important. You should create a test plan that lists the different test cases, input required, expected output of the program. Use this test plan to test your application and report the results for each test case.
Note: Once you complete coding and testing, go through the marking criteria to ensure that your application meets all the requirements. Avoid any sort of plagiarism.
What to Submit:
You should submit online the following files:
- java (this file contains class Purchase)
- Purchase Test.java (this file contains class Purchase Test) including main () method.
- docx (this file contains a brief report that includes student name, student ID number, course name, course code, UML diagram for the Purchase class, activity diagram for Option 3, display postcode, and total payable for purchase amounts of $400 and above, and test plan/results (screenshots/test cases with results to show that your application is correctly working)).