Advertisement
Sim0o0na

06. ChristmasDecoration

Jul 20th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ChristmasDecoration {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int budget = Integer.parseInt(scanner.nextLine());
  10.  
  11. String command = scanner.nextLine();
  12. while (!command.equalsIgnoreCase("Stop")) {
  13. int wordLength = command.length();
  14. int itemPrice = 0;
  15. for (int pos = 0; pos < wordLength; pos++) {
  16. int asciiValue = command.charAt(pos);
  17. itemPrice += asciiValue;
  18. }
  19. if (itemPrice <= budget) {
  20. System.out.println("Item successfully purchased!");
  21. budget -= itemPrice;
  22. } else {
  23. System.out.println("Not enough money!");
  24. return;
  25. }
  26. command = scanner.nextLine();
  27. }
  28.  
  29. System.out.printf("Money left: %d", budget);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement