Advertisement
desislava_topuzakova

Untitled

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