import cs1.Keyboard;

//To use nonstatic method go for 4 steps:
import java.text.DecimalFormat;				//1. import package

public class Arithmetic
{
	public static void main (String[ ] args)
	{
		int num1, num2 = 0;
		int sum, diff, product = 0;
		double div, expo, root = 0;		//power of a number is always double type

		System.out.print ("Enter number1: ");
		num1 = Keyboard.readInt();
		System.out.print ("Enter number2: ");
		num2 = Keyboard.readInt();

		if (num2 == 0)
		{
		  System.out.print ("Cannot divide by 0. Enter another number2: ");
		  num2 = Keyboard.readInt();
		}

		sum = num1 + num2;
		diff = num1 - num2;
		product = num1 * num2;
		div = (double) num1 / num2;				//------------casting
		expo = Math.pow(Math.max(num1, num2), Math.min(num1, num2));
		root = Math.sqrt(num1);

																	//display
		System.out.println ("\nResults:\n");
		System.out.println (num1 + " + " + num2 + " = " + sum);
		System.out.println (num1 + " - " + num2 + " = " + diff);
		System.out.println (num1 + " * " + num2 + " = " + product);
		System.out.println (num1 + " / " + num2 + " = " + div);
		System.out.println ("Minimum: " + Math.min(num1, num2) );
		System.out.println ("Maximum: " + Math.max(num1, num2) );
	    	System.out.println (Math.max(num1, num2) + " to the power of  "
	                         	+ Math.min(num1, num2) + " = " + expo);

		DecimalFormat fred;			//2. declare object var (what is fred)
		fred = new DecimalFormat("0.000");	//3. initialize variable

					//4. use the method through the object: fred.format(root);

		System.out.println ("Sq root of the " + num1 + " is: " + fred.format(root) );


		//example of casting
		long bigNum = 123456789;
		short littleNum = (short)bigNum;
		System.out.println ("\nLittleNum = " + littleNum);

		//string methods
		System.out.print ("\nEnter some text: ");
		String text = Keyboard.readString();	//text is the object (instance) name
		System.out.println ("string length: " + text.length());
		System.out.println ("Uppercase: " + text.toUpperCase());
		System.out.println ("Lowercase: " + text.toLowerCase());
		System.out.println ("First character: " + text.charAt(0));
		System.out.println ("Last character: " + text.charAt(text.length() -1));
		// -1 is because first character is #0, not #1

	}
}