In: Computer Science
I need know how to make A Java 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.
* - Up to 10 dollars: No coupon
* - From 10 to 60 dollars: 8% coupon
* - From 50 to 150 dollars: 10% coupon
* - From 150 to 210 dollars: 12% coupon
* - More than 210 dollars: 14% coupon
import java.util.Scanner; public class GroceryStore { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the amount of groceries you purchased: "); double amount = in.nextDouble(); double perc = 0; if(amount >= 210) { perc = 14; } else if(amount >= 150) { perc = 12; } else if(amount >= 50) { perc = 10; } else if(amount >= 10) { perc = 8; } double discount = amount * perc / 100; System.out.println("You will get coupon worth $" + discount); in.close(); } }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.