Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P05HairSalon {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int needMoney = Integer.parseInt(sc.nextLine());
- int price = 0;
- boolean target = false;
- String command = sc.nextLine();
- while (!command.equals("closed")) {
- if (price < needMoney) {
- String text = command;
- switch (text) {
- case "haircut":
- text = sc.nextLine();
- if (text.equals("mens")) {
- price += 15;
- } else if (text.equals("ladies")) {
- price += 20;
- } else {
- price += 10;
- }
- break;
- case "color":
- command = sc.nextLine();
- if (command.equals("touch up")) {
- price += 20;
- } else {
- price += 30;
- }
- break;
- }
- }
- if(price >= needMoney){
- target = true;
- break;
- }
- command = sc.nextLine();
- }
- if (target ) {
- System.out.printf("You have reached your target for the day!%n");
- } else {
- System.out.printf("Target not reached! You need %dlv. more.%n", Math.abs(price - needMoney));
- }
- System.out.printf("Earned money: %dlv.", price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment