|
I am doing this problem and here is the question.
A mail order house sells five products whose retail prices are a s follows: Product 1, 2.98; product 2, 4.50; product 3, 9.98; product 4, 4.49 and product 5, 6.87. write an application that reads a series of pairs of numbers as follows:
A. product number B. quantity sold
Your program should use a switch statement to determine the retail pricce for each product. It should calculate and display the total retail value of all products sold. use a sentinel controlled loop to determine when the program should stop looping and display the final results.
Thats the problem here is what I have so far I think i did it completely wrong and in some places i am totally stuck
[import java.util.Scanner;
public class MailOrder {
private String houseProducts; private int total; private int retailTotal; private int product1 = 0; private int product2 = 0; private int product3 = 0; private int product4 = 0; private int product5 = 0; public MailOrder(String name) { houseProducts= name; } public void sethouseProducts ( String name) { houseProducts = name; } public String gethouseProducts() { return houseProducts; } public void displayMessage() { System.out.printf( "Welcome to the product list for\n%s!\n]n", gethouseProducts() ); } public void inputProduct() { Scanner input = new Scanner( System.in ); int product; System.out.printf("%s\n%s\n", "Enter the Product Number from 1-5.", "Type <ctrl> z to use the end-of-file indicator to terminate input."); while ( input.hasNext() ) { product = input.nextInt(); total += product; ++retailTotal; incrementLetterretailTotal ( product ); } } public void incrementLetterretailTotal ( int product) { switch (product) { case 1: ++ 2.98; break; case 2: ++product2; break; case 3: ++product3; break; case 4: ++product4; break; case 5: ++product5; break; } }
public void displayReport() { System.out.println(" \n Retail Report:"); if ( retailTotal !=0) { double sum = (double) total + retailTotal; System.out.printf(" Total of the %d grades entered is %d\n", retailTotal, total); System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n", "Quantity sold of each product;", "Product1: ",product1, "Product2: ",product2, "Product3: ",product3, "Product4: ",product4, "Product5: ",product5); } else System.out.println( " No Products were entered" ); } } ]
|