Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PassionDays {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Double money = Double.parseDouble(scan.nextLine());
- while (true){
- String data = scan.nextLine();
- if (data.equals("mall.Enter")) break;
- }
- String input = scan.nextLine();
- int purchases = 0;
- while (!input.equals("mall.Exit")){
- for (int i = 0; i < input.length(); i++) {
- char action = input.charAt(i);
- double price;
- if (Character.isUpperCase(action)){
- price = action / 2.0;
- }
- else if (Character.isLowerCase(action)){
- price = action * 0.3;
- }
- else if (action == '%'){
- price = money / 2.0;
- }
- else if (action == '*'){
- price = -10;
- }
- else{ // everything else
- price = action;
- }
- if (price <= money){
- money -= price;
- if (action != '*'){
- purchases++;
- }
- System.out.println(price);
- System.out.println("Money " + money);
- System.out.println("Purchases: " + purchases);
- }
- else {
- System.out.println("no purchase");
- }
- // if (price <= money && action != '*'){
- // money -= price;
- // purchases++;
- // }
- // else if (action == '*'){
- // money += 10;
- // }
- }
- input = scan.nextLine();
- }
- System.out.printf("%s purchases. Money left: %.2f lv.",
- purchases, money);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement