import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Mark Young (A00000000)
 */
public class TestClassWithList {
    
    private static final Scanner KBD = new Scanner(System.in);

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ClassWithList myObject = new ClassWithList("Primes");
        
        for (int i : new int[]{2, 3, 5, 7, 11, -4, 13}) {
            try {
                myObject.add(i);
                System.out.println("Added " + i);
            } catch (IllegalArgumentException iae) {
                System.out.println("Could not add " + i);
            }
        }
        System.out.println(myObject);
        pause();
        
        // use GOOD method
        System.out.println("Getting the numbers using a SAFE method");
        List<Integer> theNumbers = myObject.getNumbersSafely();
        System.out.println("The List I got: " + theNumbers);
        System.out.println("Going to try to add -77 using the SAFE list");
        try {
            theNumbers.add(-77);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("Going to try to change first number to -77");
        try {
            theNumbers.set(0, -77);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("Going to try to delete the number at index 2");
        try {
            theNumbers.remove(2);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("After all that...");
        System.out.println(myObject);
        pause();
        
        // use BAD method
        System.out.println("Getting the numbers using the UNSAFE method");
        theNumbers = myObject.getNumbersForCheater();
        System.out.println("The List I got: " + theNumbers);
        System.out.println("Going to try to add -77");
        try {
            theNumbers.add(-77);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("Going to try to change first number to -77");
        try {
            theNumbers.set(0, -77);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("Going to try to delete the number at index 2");
        try {
            theNumbers.remove(2);
            System.out.println("It worked!");
        } catch (UnsupportedOperationException uso) {
            System.out.println("That failed");
        }
        System.out.println("After all that...");
        System.out.println(myObject);
        pause();
    }

    private static void pause() {
        System.out.println();
        System.out.print("...press enter...");
        KBD.nextLine();
        System.out.println();
    }

}
