Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ShoppingFever {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int budget = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- int spent = 0;
- int allSpent = 0;
- int clothes = 0;
- boolean isInMall = false;
- boolean statusChanged;
- while ( !(input.equals("enough") && !isInMall) ) {
- if ( input.equals("enter") ) {
- isInMall = true;
- statusChanged = true;
- }
- else if ( input.equals("leave") ) {
- isInMall = false;
- statusChanged = true;
- } else {
- if ( isInMall ){
- spent = Integer.parseInt(input);
- if ( budget < allSpent + spent ) {
- System.out.println("Not enough money.");
- } else if ( budget > allSpent + spent ) {
- //budget = budget - spent;
- allSpent += spent;
- clothes++;
- } else {
- //budget = budget - spent;
- allSpent += spent;
- clothes++;
- break;
- }
- }
- }
- input = scanner.nextLine();
- }
- System.out.printf("For %d clothes I spent %d lv and have %d lv left.", clothes, allSpent, budget - allSpent ).println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement