Advertisement
desislava_topuzakova

04. Dwarf Presents

Feb 25th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class demo4 {
  5.     public static void main(String[] agrs) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int count = Integer.parseInt(scanner.nextLine());
  9.         int budget = Integer.parseInt(scanner.nextLine());
  10.  
  11.         double moneySpent = 0;
  12.  
  13.         for (int i = 0; i < count; i++) {
  14.             String gift = scanner.nextLine().toLowerCase();
  15.  
  16.             if (gift.equals("sand clock")) {
  17.                 moneySpent += 2.20;
  18.             } else if (gift.equals("magnet")) {
  19.                 moneySpent += 1.50;
  20.             } else if (gift.equals("cup")) {
  21.                 moneySpent += 5;
  22.             } else if (gift.equals("t-shirt")) {
  23.                 moneySpent += 10;
  24.             }
  25.         }
  26.  
  27.         if (moneySpent > budget) {
  28.             double result = moneySpent - budget;
  29.             System.out.printf("Santa Claus will need %.2f more leva.", result);
  30.         } else {
  31.             double result = budget - moneySpent;
  32.             System.out.printf("Santa Claus has %.2f more leva left!", result);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement