Advertisement
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 PassionDays2 {
- 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 (char action : command.toCharArray()) {
- if (Character.isUpperCase(action)) {
- price = new BigDecimal(action).multiply(new BigDecimal(0.5));
- if (money.compareTo(price) < 0) {
- continue;
- }
- money = money.subtract(price);
- purchasesCount++;
- } else if (Character.isLowerCase(action)) {
- price = new BigDecimal(action).multiply(new BigDecimal(0.3));
- if (money.compareTo(price) < 0) {
- continue;
- }
- money = money.subtract(price);
- purchasesCount++;
- } else if (action == '%') {
- price = money.multiply(new BigDecimal(0.5));
- if (money.compareTo(price) < 0) {
- continue;
- }
- money = money.subtract(price);
- purchasesCount++;
- } else if (action == '*') {
- money = money.add(new BigDecimal(10));
- } else {
- price = new BigDecimal(action);
- if (money.compareTo(price) < 0) {
- continue;
- }
- 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));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement