Untitled

 avatar
unknown
plain_text
a year ago
1.7 kB
6
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;

        while (true) {
            System.out.print("Product Code (0 to terminate)? ");
            int code = input.nextInt();
            value = 0.0;
            if(code < 1){
                break;
            }
            
            System.out.print("Quantity? ");
            quantity = input.nextInt();
            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