/** 
 * This class simply shows some operations for discussion
 * @author Nancy Harris
 * @version V1
 */
public class Decisions
{
	/** 
	 * Function just demonstrates some if statements.  May not compile
	 * @param args Command line arguments
	 */
	public static void main(String args[])
	{
		// Code fragments
		boolean flag1;
		boolean flag2;
		int testNum1;
		int testNum2;
		
		int[] testArray = {1, 2, 3};
		
		Scanner kb = new Scanner(System.in);
	
		flag1 = true;
		flag2 = false;
		testNum1 = 0;
		testNum2 = 15;
	
		// How do I test flag1 for true?
		if (                 )
			System.out.println("flag1 is true");
		else
			System.out.println("flag1 is false");
	
		// How do I test flag1 for false?
		if (               )
			System.out.println("flag1 is false");
		else
			System.out.println("flag1 is true");
			
		// What do you think will happen here?
		if (flag1 = true)
			System.out.println("flag1 is true");
		else 
			System.out.println("flag1 is false");
	
		//Compare to what will happen here?  Compiler error
		// or run time error or no error
		if (testNum1 = 0)
			System.out.println("testNum1 is 0");
		else
			System.out.println("testNum1 is not 0");
	
		// break statements
		while (testNum2 > testNum1)
		
			// if makes sure that we are not diverging
			if (Math.abs(testNum2 - testNum1) > 25)
				break;  // is this a "legal" form of a break?
			else
				testNum2--;
	
		// short circuited operations
		// if flag1 is false, the test of flag 2 is not done
		if (flag1 && testNum1 < 0)
			System.out.println("flag1 is true and testNum1 is neg");
		else
			System.out.println("flag1 is false or testNum1 is pos" +
				" or both");
				
		// short circuited operations
		// what will happen here?
		if (flag2 && testArray[5] == 5)
			System.out.println("flag2 true and array[5] = 5");
		else
			System.out.println("the condition is not true");

		// Mutually exclusive conditions - what is a better way to write
		// this?
		if (flag1)
			System.out.println("flag1 is true");
		
		if (!flag1)
			System.out.println("flag1 is false");
		
		// Can you rewrite the above without an if?	
				
		switch(testNum1)
		{
			case 2:
			case 4:
			case 8:
				System.out.println("This will print for 2, 4, or 8);
				break;
			case 3:
			case 5:
			case 7:
				System.out.println("This will print for 3, 5, or 7);
			case 1:
			case 0:
				System.out.println("This will print for 0, 1, 3, 5, or 7);
				break;
			default:
				System.out.println("This will print for <0 or >8);
		}
		
		// So what is wrong with this bit of code?
		
		System.out.print("Enter an integer: ");
		
		if (!kb.hasNextInt())
		{
			System.out.println("Leaving, goodbye");
			System.exit(3);
		}
		else
		{
			testNum1 = kb.nextInt();
		}

		System.out.print("Enter an integer: ");

		if (!kb.hasNextInt())
		{
			System.out.println("Leaving, goodbye");
			System.exit(4);
		}
		else
		{
			testNum2 = kb.nextInt();
		}
	}
}
