Skip to main content

L03

Coupons.java

import java.util.Scanner;

public class Coupons {
    public static void main(String[] args) {
        Scanner myScanner = new Scanner(System.in);
        System.out.print("Please enter the cost of your groceries: ");

        double amount = Double.parseDouble(myScanner.nextLine());

        System.out.print("You win a discount of $");
        if (amount < 10)
            System.out.print("0.");
        else if (amount <= 60)
            System.out.printf("%.2f. (8%% of your purchase)", .08 * amount);
        else if (amount <= 150)
            System.out.printf("%.2f. (10%% of your purchase)", .1 * amount);
        else
            System.out.printf("%.2f. (14%% of your purchase)", .14 * amount);
    }
}