Advertisement
lleu

Calculate discounts

Sep 11th, 2019
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Coupon {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner input = new Scanner(System.in);
  8.  
  9. //Varibles
  10. double spent;
  11. double coupon;
  12.  
  13. //Input from keyboard
  14. System.out.println("Please enter the cost of your groceries: ");
  15. spent = input.nextDouble();
  16.  
  17. //Calculate discount
  18. if (spent<10)
  19.  
  20. System.out.print("You did not earn a discount");
  21.  
  22. else if (spent>10 && spent<=60) {
  23.  
  24. coupon = spent * 0.08;
  25. System.out.print("You win a discount coupon of " + coupon + "(8% of your purchase)");
  26. }
  27. else if (spent>60 && spent<=150) {
  28.  
  29. coupon = spent * 0.1;
  30. System.out.print("You win a discount coupon of " + coupon + "(10% of your purchase)");
  31. }
  32. else if (spent>150 && spent<=210) {
  33.  
  34. coupon = spent * 0.12;
  35. System.out.print("You win a discount coupon of " + coupon + "(12% of your purchase)");
  36. }
  37. else if (spent>210) {
  38.  
  39. coupon = spent * 0.14;
  40. System.out.print("You win a discount coupon of " + coupon + "(14% of your purchase)");
  41. }
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement