Question

All code will be in Java, and there will be TWO source code. I. Write the...

All code will be in Java, and there will be TWO source code.

I. Write the class  MailOrder to provide the following functions:

At this point of the class, since we have not gone through object-oriented programming and method calling in detail yet, the basic requirement in this homework is process-oriented programming with all the code inside method processOrderof this class. Inside method processOrder, we still follow the principles of structured programming.  

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 10012. Row 0 of the array for the unit price is to hold the unit price of product 10012.  Row 0 of the array for the current inventory level is to hold the current inventory level of product 10012, etc.

The system should accept one incoming sales order.  In this sales order, the 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.   Then the system should end the execution of the system.

Detailed description of how the system should work is as follows:

When execution of the system is started:

  • Correctly define and initialize all variables
  • Display the following main question:

Please enter the next product number to buy or -99 = end:<user enters a product number or -99>

You can assume that the user will enter an integer value.  

  • While the just-received product number is not -99

{

  • Search for the corresponding product number in the product number array.
  • If this product is found:
  • If the current inventory level is > 0,
  1. display “Unit Price: <the unit price of this item>“ and “Current Quantity Available: <the current inventory level of this item>” and

(b)ask for the quantity ordered, “Enter quantity ordered:”<user enters the quantity ordered>.

You can assume that the user will key in a positive integer value.

            

If the quantity available is smaller than the quantity ordered, sell only the quantity available. Otherwise, sell the ordered quantity.

Display “Quantity Sold: <the quantity that can be sold>

Calculate the amount for this item as Unit Price * Quantity Sold.

Display the amount for this item: “Item Amount: $ <the amount

            calculated>”

                                                            Add this amount to the current order total amount.

                                                            Since this item has been sold, update the current inventory level of this

                                                                        item.

            Else this means inventory level is 0: display “This item is out of stock. Please pick another one.

                              Else this product is not found, display an error message “Invalid product number.”

  • Display the following main questionagain before the end of the while loop

Please enter the next product number to buy or -99 = end):<user enters a product number or -99>

You can assume that the user will enter an integer value.

} // end of the while loop

  • When control comes to here, this means the user has entered a -99 for the next product number, the system displays the total amount of this order. For example:

Order Total Amount:         $  72.83

  • Then, the system displays the message “Bye” and execution ends.

II. Write the class MailOrderTest to provide the following functions:

In method mainof this application, instantiate an object of MailOrderand call the method processOrderof this MailOrderobject to start order processing.

DO NOT USE Until loop (the “do-while” loop in Java)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class MailOrder

{

public processOrder()

{

int[] product_number={10011, 10012, 10013, 10014, 10015};

float[] unit_price={10.5, 11.2, 20.4, 30, 25};

int[] inventory_level={10, 20, 30, 40,50};

double total_amt=0;

double final_amt=0

Scanner myObj = new Scanner(System.in);  // Create a Scanner object
    System.out.println("Please enter the next product number to buy or -99 = end");

    int no = myObj.nextInt();  // Read user input

while(no !=-99)

{

for(int i=0;i<product_number.length;i++)

{    

            if(product_number[i] == no)

{    

if(inventory_level>0)

{

  System.out.println("current inventory level is"+inventory_level[i]);

   System.out.println("unit price is"+unit_pricel[i]);

  System.out.println("Enter quatity of that product");

  int quantity = myObj.nextInt();

if(quantity<= inventory_level[i] )

{

  System.out.println("product sold as per your requirement"+ quantity);

total_amt=quantity*unit_price;

  System.out.println("Total amount will be"+ total_amt);

  System.out.println("Remaining quantity is"+ inventory_level[i]-quantity);

final_amt=final_amt+total_amt;

System.out.println("Final amount will be"+ final_amt);

}

else

{

System.out.println("we can sell only what we have "+ inventory_level[i]);

total_amt=inventory_level[i]*unit_price;

  System.out.println("Total amount will be"+ total_amt);

System.out.println("now product is out of stock please pick another one");

final_amt=final_amt+total_amt;

System.out.println("Final amount will be"+ final_amt);

}

}

}

else{System.out.println("This product is not available ");}

System.out.println("Please enter the next product number to buy or -99 = end");

}//end of while loop

   System.out.println("Total amout of all product is"+final_amt);

    System.out.println("Bye");

  

            }    

}

public class MailOrderTest

{

public static void main(String args[])

{

  MailOrder m = new MailOrder();

m.processOrder();

}

}

Add a comment
Know the answer?
Add Answer to:
All code will be in Java, and there will be TWO source code. I. Write the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java application that prompts the user for pairs of inputs of a product number...

    Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1    1...

  • Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items...

    Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when user enter "0", stop the loop. - User enter item name, price, quantity, save these info and subtotal to array. - increase "count++" -conver price(decimal, Convert.ToDecimal() ) and quantity(int) to do mulplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and...

  • java Invoice class

    Create a class named Invoice that contains fields for an item number, name, quantity, price, and total cost. Create insurance methods that set the item name, quantity,and price. Whenever the price for quantity is set, recalculate the total (price times quantity). Also include a display Line() method that displays the item number,name, quantity, price, and total cost. Make sure you include a class named TestInvoice whose main method () declares three Invoice items. Create a method that prompts the user...

  • What is the java code for this. The goal of this lab is to write two...

    What is the java code for this. The goal of this lab is to write two programs, Summation and Prime, that execute simple tasks. The first computes the summation of integers within a range with a gap that the user specifies. The second tests whether the integer that the user enters is a square and if not, whether it is composite or prime. Summation Let us see some execution examples first, to get the sense of how the program works....

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized...

    Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized with the following strings: “Einstein”, “Newton”, “Copernicus”, and “Kepler”. 2. Assume names in an Integer array with 20 elements. Write a pseudocode algorithm a For Loop that displays each element of the array. 3. Assume the arrays numberArray1 and numberArray2 each have 100 elements. Write a pseudocode algorithm that copies the values in numberArray1 to numberArray2 . 4. Write a pseudocode algorithm for a...

  • Please explain each line of code, all code will be in Java. Thank you JKL Restaurant...

    Please explain each line of code, all code will be in Java. Thank you JKL Restaurant maintains a members’ club for its customers.  There are three levels of membership: (1) Basic, (2) Silver, and (3) Gold. A certain member has to be exactly a Basic, Silver, or Gold member at any point in time.  Whenever a member spends money at JKL, he/she gets points and as these points are accumulated, one can redeem one or more $20 dining certificates.  Each Gold member can...

  • Java Programming Write a method named isEven that accepts an integer argument. The method should return...

    Java Programming Write a method named isEven that accepts an integer argument. The method should return true if the argument is even, or false if not. The program’s main method should use a loop to generate a random integer. The number of random integers is provided by a user, who must enter a number greater than 10. The loop should then invoke the isEven method to determine whether each integer is even or odd, display the random number and the...

  • Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers....

    Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers. This program will have array that holds 10 random integers from 1 to 5. Output the 10 random numbers to the screen using an enhanced for loop. This program will also have a method called frequency that takes an integer array as the parameter and it will return an array that holds the frequency of numbers. Index 0 will hold the frequency of 1,...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT