// Practical 7A (Revision) - Q1
// Marcus Ward
// 26/10/2011
/* Program will allow user to enter 2 values and an operator.
Using a switch statement the program will display the result on screen. */
import java.util.Scanner;
public class CalculatorProgram
{
public static void main(String[] args)
{
Scanner keyboardIn = new Scanner(System.in);
double num1, num2; // declare variables
char operator;
System.out.println("Enter 1st value"); // get user input
num1 = keyboardIn.nextDouble();
System.out.println("Enter operator");
operator = keyboardIn.next.charAt(0);
System.out.println("Enter 2nd value");
num2 = keyboardIn.nextDouble();
switch (operator) { // create calculator and display ouput
case '+':
System.out.println(num1 + num2);
break;
case '-':
System.out.println(num1 - num2);
break;
case '*':
System.out.println(num1 * num2);
break;
default:
System.out.println(num1 / num2);
break;
}
}
}