Martes, Nobyembre 29, 2011

A mail order house sales 5 product whose retail price as follows:PRODUCT1: $2.98, PRODUCT2: $4.50, PRODUCT3: $9.98,PRODUCT4: $4.49, & PRODUCT5: $6.87, Write an application that reads a series of pair of numbers as Follows: A) Product number B) Quantity Sold ..... The program should use a switch statement, determine the retail price for each product. it should calculate and display the total retail value of all product sold.

import java.io.*;
public class sample4 {

 
    public static void main(String[] args)throws IOException {
         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         double product1 = 2.98,product2=4.50,product3=9.98,product4=4.49,product5=6.87;
         int hold,value;


         double total;
         System.out.print("Choices of Product! \n[1]Product1 \n[2]Product2 \n[3]Product3 \n[4]Product4 \n[5]Product5 \nChoose Product : ");
         hold=Integer.parseInt(in.readLine());
         switch(hold){
             case 1:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                total=product1*value;
                 System.out.println("Product number 1:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;
             case 2:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product2*value;
                 System.out.println("Product number 2:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;
             case 3:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product3*value;
                 System.out.println("Product number 3:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;

              case 4:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product4*value;
                 System.out.println("Product number 4:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;

            case 5:
                 System.out.println("Quantity you want?: ");
                value =   Integer.parseInt(in.readLine());
                 total=product5*value;
                 System.out.println("Product number 5:");
                 System.out.println("Quantity sold: "+value);
                 System.out.print("Amount to be paid: "+total+"$");
                 break;            }
    }

}

Walang komento:

Mag-post ng isang Komento