desislava_topuzakova

Untitled

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