A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows the percent used to calculate the coupon awarded for different amounts spent. Write a program that calculates and prints the value of the coupon a person can receive based on groceries purchased.
Code:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Groceries cost: ");
double groceries_c = input.nextDouble();
input.close();
double discount = (groceries_c < 10)? 0:
(groceries_c < 61)? groceries_c * 0.08:
(groceries_c < 151)? groceries_c * 0.10:
(groceries_c < 211)? groceries_c * 0.12:
groceries_c * 0.14;
System.out.println("You win a discount coupon of " + discount);
}
}