package ae;

import java.io.*;
import java.util.*;
import java.util.Scanner;

// to enable assertions, put "-ea" in Run/Run Configurations.../Arguments/VM arguments

class TooLowException extends Exception { }
class TooHighException extends Exception { }

public class AssertExcept {
	
	String name = "random name";
	int index = 32;
	
	void AssertTest() {
		
		Scanner input = new Scanner( System.in );
	         
		System.out.print( "Enter a number between 0 and 10: " );
		int number = input.nextInt();

		// assert that the absolute value is >= 0
		assert ( number >= 0 && number <= 10 ) : "bad number: " + number;

		System.out.printf( "You entered %d\n", number );
	
	}
	
	void foo(double y) throws TooLowException, TooHighException {
		
		if (y < 0)
			throw new TooLowException();
		else if (y > 100)
			throw new TooHighException();
	}
	
	public static void main(String[] args) 
	{
		// pretend we just asked the user for two numbers, the second greater than the first
		int a = 5;
		int b = 3;
		
		// this will fail...change b to > 5 to fix
		assert (b > a) : "a = " + a + ", b = " + b;
		
		AssertExcept T = new AssertExcept();
		
		T.AssertTest();
		
		int i = 0;
		
		double x = 50.3;
		
		try {

			while (i++ < 10) {
				T.foo(x);
				x -= 3.3;
			}
	
		} catch (TooLowException lowex) {
			System.out.println("Low Exception!");
			lowex.printStackTrace();
		} catch (TooHighException highex) {
			System.out.println("High Exception!");
			highex.printStackTrace();
		} finally {
			System.out.println("All done!");
		}
	
		System.out.println(x + " " + i);
	}
	
}
	
