Guest User

Untitled

a guest
Dec 18th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.RoundingMode;
  3. import java.util.Scanner;
  4.  
  5. public class PassionDays {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         BigDecimal money = new BigDecimal(scanner.nextLine());
  10.         String command = scanner.nextLine();
  11.  
  12.         BigDecimal price = new BigDecimal(0);
  13.         int purchasesCount = 0;
  14.  
  15.         while (!command.equals("mall.Enter")) {
  16.             command = scanner.nextLine();
  17.         }
  18.         command = scanner.nextLine();
  19.         while (!command.equals("mall.Exit")) {
  20.             for (int i = 0; i < command.length(); i++) {
  21.                 if (command.charAt(i) >= 'A' && command.charAt(i) <= 'Z') {
  22.                     price = new BigDecimal(command.charAt(i)).multiply(new BigDecimal(0.5));
  23.                 } else if (command.charAt(i) >= 'a' && command.charAt(i) <= 'z') {
  24.                     price = new BigDecimal(command.charAt(i)).multiply(new BigDecimal(0.3));
  25.                 } else if (command.charAt(i) == '%') {
  26.                     price = money.multiply(new BigDecimal(0.5));
  27.                 } else if (command.charAt(i) == '*') {
  28.                     money = money.add(new BigDecimal(10));
  29.                     price = money.add(new BigDecimal(1));
  30.                 } else {
  31.                     price = new BigDecimal(command.charAt(i));
  32.                 }
  33.                 if (price.compareTo(money) <= 0) {
  34.                     money = money.subtract(price);
  35.                     purchasesCount++;
  36.                 }
  37.             }
  38.             command = scanner.nextLine();
  39.         }
  40.         if (purchasesCount == 0) {
  41.             System.out.printf("No purchases. Money left: %s lv.%n",
  42.                     money.setScale(2, RoundingMode.HALF_UP));
  43.         } else {
  44.             System.out.printf("%d purchases. Money left: %s lv.%n", purchasesCount,
  45.                     money.setScale(2, RoundingMode.HALF_UP));
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment