galinyotsev123

ProgBasics05while-Loop-P07waterDispenser

Jan 7th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P07waterDispenser {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int counter = 0;
  7. int glassFilled = 0;
  8. int glassVolume = Integer.parseInt(scanner.nextLine());
  9.  
  10. while (glassFilled < glassVolume) {
  11. String command = scanner.nextLine();
  12.  
  13. switch (command) {
  14. case "Easy":
  15. glassFilled += 50;
  16. counter++;
  17. break;
  18. case "Medium":
  19. glassFilled += 100;
  20. counter++;
  21. break;
  22. case "Hard":
  23. glassFilled += 200;
  24. counter++;
  25. break;
  26. }
  27. }
  28. if (glassFilled > glassVolume) {
  29. System.out.printf("%dml has been spilled.", glassFilled - glassVolume);
  30.  
  31. } else if (glassFilled == glassVolume) {
  32. System.out.printf("The dispenser has been tapped %d times.", counter);
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment