Untitled

 avatar
unknown
plain_text
a year ago
2.4 kB
10
Indexable
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package purchasev1;

import java.util.Scanner;

/**
 *
 * @author nguyennt
 */
public class PurchaseV1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int quantity;
        double value;
        double totalValue = 0.0;
        int code;

        while (true) {
            value = 0.0;
            
            while(true){
                System.out.print("Product Code (0 to terminate)? ");
                code = input.nextInt();
                if(code == 0){
                    break;
                }
                if(code > 0 && code < 6){
                     break;
                    
                }else{
                    System.out.println("product code must be in the range of 1-5");
                }
                
            }
            
            if (code ==0){
                break;
            }
            
            while(true){
                System.out.print("Quantity? ");
                quantity = input.nextInt();
                if(quantity < 1){
                    System.out.println("Quantity must be > 0. Reenter the value");
                }else{
                    break;
                }
            }
           
            switch (code) {
                case 1:
                    value += (2.98 * quantity);
                    break;
                case 2:
                    value += (4.50 * quantity);
                    break;
                case 3:
                    value += (9.98 * quantity);
                    break;
                case 4:
                    value += (4.49 * quantity);
                    break;
                case 5:
                    value += (6.87 * quantity);
                    break;
                    
                default:
                    break;
            }

            totalValue += value;
            System.out.printf("Value of purchase is $%.2f\n", value);

        }

        System.out.printf("Value of all purchases is $%.2f\n", totalValue);

    }

}
Editor is loading...
Leave a Comment