Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class App2 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         double buget = Double.parseDouble(scan.nextLine());
  7.         String input = scan.nextLine();
  8.         int i = 1;
  9.         double price = 0;
  10.         double moneyNeed = 0;
  11.         double moneySpend = 0;
  12.  
  13.         while (!input.equals("Finish")) {
  14.  
  15.             if (input.equals("Star")) {
  16.                 price = 5.69;
  17.                 if (i == 3) {
  18.                     price = price - (price * 0.3);
  19.                 }
  20.                 buget = buget - price;
  21.                 moneySpend=moneySpend+price;
  22.  
  23.             } else if (input.equals("Angel")) {
  24.                 price = 8.49;
  25.                 if (i == 3) {
  26.                     price = price - (price * 0.3);
  27.                 }
  28.                 buget = buget - price;
  29.                 moneySpend=moneySpend+price;
  30.  
  31.             } else if (input.equals("Lights")) {
  32.                 price = 11.20;
  33.                 if (i == 3) {
  34.                     price = price - (price * 0.3);
  35.                 }
  36.                 buget = buget - price;
  37.                 moneySpend=moneySpend+price;
  38.             } else if (input.equals("Wreath")) {
  39.                 price = 15.50;
  40.                 if (i == 3) {
  41.                     price = price - (price * 0.3);
  42.                 }
  43.                 buget = buget - price;
  44.                 moneySpend=moneySpend+price;
  45.             } else if (input.equals("Candle")) {
  46.                 price = 3.59;
  47.                 if (i == 3) {
  48.                     price = price - (price * 0.3);
  49.                 }
  50.                 buget = buget - price;
  51.                 moneySpend=moneySpend+price;
  52.             }
  53.             input = scan.nextLine();
  54.  
  55.             if (buget < 0) {
  56.                 moneyNeed = Math.abs(buget);
  57.                 System.out.println("Not enough money! You need " + moneyNeed + "lv more.");
  58.             }
  59.  
  60.  
  61.             i++;
  62.         }
  63.         if (input.equals("Finish") || buget >= 0) {
  64.             System.out.println("Congratulations! You bought everything!");
  65.         }
  66.         System.out.print(i - 1 );
  67.         System.out.printf(" items -> %.2flv spent.",moneySpend);
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement