Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class PassionDays {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- BigDecimal money = new BigDecimal(scanner.nextLine());
- String command = scanner.nextLine();
- BigDecimal price = new BigDecimal(0);
- int purchasesCount = 0;
- while (!command.equals("mall.Enter")) {
- command = scanner.nextLine();
- }
- command = scanner.nextLine();
- while (!command.equals("mall.Exit")) {
- for (int i = 0; i < command.length(); i++) {
- if (command.charAt(i) >= 'A' && command.charAt(i) <= 'Z') {
- price = new BigDecimal(command.charAt(i)).multiply(new BigDecimal(0.5));
- } else if (command.charAt(i) >= 'a' && command.charAt(i) <= 'z') {
- price = new BigDecimal(command.charAt(i)).multiply(new BigDecimal(0.3));
- } else if (command.charAt(i) == '%') {
- price = money.multiply(new BigDecimal(0.5));
- } else if (command.charAt(i) == '*') {
- money = money.add(new BigDecimal(10));
- price = money.add(new BigDecimal(1));
- } else {
- price = new BigDecimal(command.charAt(i));
- }
- if (price.compareTo(money) <= 0) {
- money = money.subtract(price);
- purchasesCount++;
- }
- }
- command = scanner.nextLine();
- }
- if (purchasesCount == 0) {
- System.out.printf("No purchases. Money left: %s lv.%n",
- money.setScale(2, RoundingMode.HALF_UP));
- } else {
- System.out.printf("%d purchases. Money left: %s lv.%n", purchasesCount,
- money.setScale(2, RoundingMode.HALF_UP));
- }
- }
- }
Add Comment
Please, Sign In to add comment