import java.util.Scanner;
public class ChairExample {
    
    public static void main(String[] args) {
        Chair myChair = new Chair("blue");   
        
        printChairInformation(myChair);
        
        myChair.setOccupiedBy("Vswe");
        
        printChairInformation(myChair);
        
        Scanner myScanner = new Scanner(System.in);
        
        Chair[] officeChairs = new Chair[5];
        for (int i = 0; i < officeChairs.length; i++) {
            officeChairs[i] = new Chair("green");
        }
        
        
        while (true) {
            //print all the options
            System.out.println("The office chairs:");
            printChairInformation(officeChairs);
            System.out.println((officeChairs.length + 1) + ". Exit");
            
            System.out.println("\nSelect a chair");
            int option = myScanner.nextInt();
            
            //valid chair
            if (option >= 1 && option <= officeChairs.length) {
                Chair selectedChair = officeChairs[option - 1];
                printChairInformation(selectedChair);
                
                if (selectedChair.isBroken()) {
                    
                    //allow the user to repair the chair
                    System.out.println("Do you want to repair this chair? (yes/no)");
                    if (myScanner.next().toLowerCase().equals("yes")) {
                        selectedChair.repair();
                    }
                }else if (selectedChair.isOccupied()) {
                    
                    //allow the user to remove the person from the chair
                    System.out.println("Do you want to remove the person fron this chair? (yes/no)");
                    if (myScanner.next().toLowerCase().equals("yes")) {
                        selectedChair.setUnoccupied();
                    }
                }else{
                    //allow the user to place a person on the chair
                    System.out.println("Who should sit here?");
                    selectedChair.setOccupiedBy(myScanner.next());
                }
            }else if (option == officeChairs.length + 1) {
                break;
            }else{
                System.out.println("Invalid option");
            }
        }
    }   
    
    //print a list of chairs
    static void printChairInformation(Chair[] chairs) {
        for (int i = 0; i < chairs.length; i++) {
            System.out.print((i + 1) + ". ");
            printChairInformation(chairs[i]);
        }
    }
    
    //print a chair
    static void printChairInformation(Chair chair) {
        System.out.print("This " + chair.getColor() + " chair is ");
        if (chair.isBroken()) {
            System.out.println("broken. Please repair it");         
        }else if (chair.isOccupied()) {
            System.out.println("occupied by " + chair.getOccupiedBy());
        }else {
            System.out.println("empty");
        }
        
    }
}