// package cse.oop2.ch13_3;


public class Washer2 {
    
    private int userInput;
    
    public Washer2(int userInput) {
        this.userInput = userInput;
    }
    
    public void foo() {
        Laundry laundry = new Laundry(userInput);
        try {
            laundry.doLaundry();
            System.out.println("세탁이 완료되었습니다!");
        } catch (ClothingException ex) {
            System.out.printf("예외: %s%n", ex.getMessage());
            System.out.println("세탁이 되지 않았습니다!");
        }
    }
    
    public static void main(String[] args) throws ClothingException {
        int userInput = -1;
        if (args.length >= 1) {
            if (args[0].matches("^-?\\d+$")) {
                System.out.println("숫자가 맞습니다.");
                userInput = Integer.parseInt(args[0]);
            } else {
                System.out.println("숫자가 아닙니다.");
            }
        }
        System.out.printf("입력 값은 %d입니다.%n", userInput);
        
        Washer2 w = new Washer2(userInput);
        w.foo();
    }

}


class Laundry {
    
    private int userInput;
    
    public Laundry(int userInput) {
        this.userInput = userInput;
    }
    
    public void doLaundry() throws ClothingException {
        if (userInput < 0) {
            throw new ClothingException();
        } else {
            System.out.println("세탁을 합니다.");
        }
    }
    
}


class ClothingException extends Exception {
    
    public ClothingException() {
        super("ClothingException");
    }
    
}