Advertisement
desislava_topuzakova

Untitled

Jun 20th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HairSalon {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int moneyGoal = Integer.parseInt(scanner.nextLine());
  9. int collectedMoney = 0;
  10.  
  11. String input = scanner.nextLine();
  12. String service = "";
  13. boolean isCompleted = false;
  14.  
  15. while (!input.equals("closed")) {
  16.  
  17. service = scanner.nextLine();
  18. if (input.equals("haircut")) {
  19. switch (service) {
  20. case "mens":
  21. collectedMoney += 15;
  22. break;
  23. case "ladies":
  24. collectedMoney += 20;
  25. break;
  26. case "kids":
  27. collectedMoney += 10;
  28. break;
  29. }
  30. }
  31. else {
  32. if (service.equals("touch up"))
  33. collectedMoney += 20;
  34. else
  35. collectedMoney += 30;
  36. }
  37.  
  38.  
  39. if(collectedMoney >= moneyGoal)
  40. {
  41. isCompleted = true;
  42. break;
  43. }
  44. input = scanner.nextLine();
  45. }
  46.  
  47. if (isCompleted) {
  48. System.out.println("You have reached your target for the day!");
  49. }
  50. else {
  51. int diff = moneyGoal - collectedMoney;
  52. System.out.printf("Target not reached! You need %dlv. more.%n", diff);
  53. }
  54.  
  55. System.out.printf("Earned money: %dlv.", collectedMoney);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement