// Steve Giovenco
// 7/7/03
// Solution to 2003 BHCSI Introduction to Java Program #7

import java.io.*;

public class FuncCalc
{
	//input stream
	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	
	//return sum of a and b
	public static int add(int a, int b) {return a + b;}
	
	//return difference of a and b
	public static int subtract(int a, int b) {return a - b;}
	
	//return product of a and b
	public static int multiply(int a, int b) {return a * b;}
	
	//return quotient of a and b
	public static double divide(int a, int b)
	{
		double tmp = a;
		return tmp / b;
	}
	
	//return a raised to the b-th power
	public static int power(int a, int b)
	{
		int tmp = 1;
		for (int i=0; i<b; i++)
			tmp *= a;
		return tmp;
	}
		
	//prompt the user for an integer
	public static int prompt(String s) throws IOException
	{
		System.out.print(s);
		return Integer.parseInt(in.readLine());
	}
	
	public static void main (String[] args) throws IOException
	{
		int choice;
		do 
		{
			//output menu
			System.out.println("Main Menu\n1.Add\n2.Subtract\n3.Multiply");
			System.out.println("4.Divide\n5.Raise to a power\n6.Quit");
			
			//get user input
			choice = prompt("Your choice: ");
			
			switch (choice)
			{
				case 1: //add
					int a = prompt("Enter an integer: ");
					int b = prompt("Enter another integer: ");
					System.out.println("\n" + a + "+" + b + "=" + add(a,b));
					break; //prevent from going into case 2
				case 2: //subtract
					a = prompt("Enter an integer: ");
					b = prompt("Enter another integer: ");
					System.out.println("\n" + a + "-" + b + "=" + subtract(a,b));
					break;
				case 3: //multiply
					a = prompt("Enter an integer: ");
					b = prompt("Enter another integer: ");
					System.out.println("\n" + a + "*" + b + "=" + multiply(a,b));
					break;
				case 4: //divide
					a = prompt("Enter an integer: ");
					b = prompt("Enter another integer: ");
					System.out.println("\n" + a + "/" + b + "=" + divide(a,b));
					break;
				case 5: //power
					a = prompt("Enter an integer: ");
					b = prompt("Enter another integer: ");
					System.out.println("\n" + a + "^" + b + "=" + power(a,b));
					break;
				case 6: //quit
					System.out.println("\nThank you for using this calculator");
					break;
				default: //invalid input
					System.out.println("\nInvalid input");
			}
			System.out.println("\n"); //for formatting output
		} 
		while (choice != 6); //6 == quit
	}
}
