Advertisement
marking2112

NLShoppingManiac

Oct 23rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ShoppingFever {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int budget = Integer.parseInt(scanner.nextLine());
  8.         String input = scanner.nextLine();
  9.  
  10.         int spent = 0;
  11.         int allSpent = 0;
  12.         int clothes = 0;
  13.  
  14.         boolean isInMall = false;
  15.         boolean statusChanged;
  16.  
  17.         while ( !(input.equals("enough") && !isInMall) ) {
  18.  
  19.             if ( input.equals("enter") ) {
  20.                 isInMall = true;
  21.                 statusChanged  = true;
  22.             }
  23.             else if ( input.equals("leave") ) {
  24.                 isInMall = false;
  25.                 statusChanged = true;
  26.             } else {
  27.                 if ( isInMall ){
  28.                     spent = Integer.parseInt(input);
  29.                     if ( budget < allSpent + spent ) {
  30.                         System.out.println("Not enough money.");
  31.                     } else if ( budget > allSpent + spent ) {
  32.                         //budget =  budget - spent;
  33.                         allSpent += spent;
  34.                         clothes++;
  35.                     } else {
  36.                         //budget =  budget - spent;
  37.                         allSpent += spent;
  38.                         clothes++;
  39.                         break;
  40.                     }
  41.                 }
  42.  
  43.             }
  44.  
  45.             input = scanner.nextLine();
  46.         }
  47.  
  48.         System.out.printf("For %d clothes I spent %d lv and have %d lv left.", clothes, allSpent, budget - allSpent ).println();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement