/**
 * Created by haozewang on 17/5/17.
 */

import java.util.Scanner;

public class Test {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        ColorImplementor green = new GreenImplementor();
        ColorImplementor yellow = new YelloImplementor();

        Rectangle rectangle = new Rectangle(3,4);
        Triangle triangle = new Triangle(3);

        while (true) {
            String shapeChoice;
            do {
                System.out.println("Choose (r)ectangle or (t)riangle.");
                shapeChoice = scan.next();
            } while (shapeChoice.length() == 0 || (shapeChoice.charAt(0) != 'r' && shapeChoice.charAt(0) != 't'));
            Shape shape = shapeChoice.charAt(0) == 'r' ? rectangle : triangle;

            String colorChoice;
            do {
                System.out.println("Choose (g)reen or (y)ellow.");
                colorChoice = scan.next();
            } while (colorChoice.length() == 0 || (colorChoice.charAt(0) != 'g' && colorChoice.charAt(0) != 'y'));

            // Choosing implementation details at run-time rather than compile-time
            if (colorChoice.charAt(0) == 'g') {
                shape.setColor(green);
            } else {
                shape.setColor(yellow);
            }

            shape.colorShape();
        }

    }
}
