MP Mail Order House sells five products. Product numbers, unit prices, and curre
ID: 663147 • Letter: M
Question
MP Mail Order House sells five products. Product numbers, unit prices, and current inventory levels, are as follows:
Product No
Unit Price
Current Inventory Level
1
$2.98
10
2
$4.50
8
3
$9.98
15
4
$4.49
3
5
$6.87
0
I. Write the class MailOrder to provide the following functions:
Set up one one-dimensional array for each field: product number (integer), unit price (double), and current inventory level (integer) in main memory to hold the above product information. There should be five rows (0 to 4) in each array, one for each item. For example, row 0 of the array for the product number is to hold the product number of product 1. Row 0 of the array for the unit price is to hold the unit price of product 1. Row 0 of the array for the current inventory level is to hold the current inventory level of product 1, etc.
The system should accept incoming sales orders until the user chooses to quit. In each sales order, a user can buy more than one item. For each item, the system accepts the product number and the quantity to be purchased. The system retrieves the correct unit price and current inventory level for that particular item. The system only sells up to the current inventory available. If the system can sell x pieces of this item in this order, the system calculates and displays the total amount for this item and also decreases the item inventory level by x immediately. When the user has finished keying in all the items of an order, the system displays the order total amount.
When the user says there are no more orders, the system displays the daily sales total. This is the total sales amount of all the orders processed. Then the system should end the execution of the system.
Detailed description of how the system should work is as follows:
When the system is run:
Display the following main question:
Please enter the next action (1=Enter a new order and 2=Bye): <user enters 1 or 2>
If the user enters any value other than 1 and 2, then the system displays an error message and displays the above question until the user has entered either 1 or 2.
If the user chooses entering a new order (1), then display the next product number question:
Please enter the next product number to buy (1
Product No
Unit Price
Current Inventory Level
1
$2.98
10
2
$4.50
8
3
$9.98
15
4
$4.49
3
5
$6.87
0
Explanation / Answer
Complete Program:
// File: MailOrder.java
import java.util.Scanner;
public class MailOrder
{
private int[] productNumbers = {1, 2, 3, 4, 5};
private double[] unitPirces = {2.98, 4.50, 9.98, 4.49, 6.87};
private int[] currentInventoryLevels = {10, 8, 15, 3, 0};
public MailOrder()
{}
public void processOrders()
{
Scanner input = new Scanner(System.in);
int action;
int prodNum;
int quantityOrdered;
double amountForItem;
double orderTotalAmount;
double dailySalesTotalAmount = 0;
do
{
orderTotalAmount = 0;
System.out.print("Please enter the next action (1=Enter a new order and 2=Bye): ");
action = input.nextInt();
switch(action)
{
case 1:
do
{
System.out.print(" Please enter the next product number to buy (1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.