Assignemnt #73 Baby Calculator

Code

    Name: Iaroslav Titov
    Period: 7
    Project Name: BabyCalculator
    File Name: BabyCalculator.java
    Date: 1/11/2015
    
import java.util.Scanner;
import java.util.InputMismatchException;

public class BabyCalculator
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);

		double a, b, c;
		String op;

		try {
			do {
				System.out.print("> ");
				a = keyboard.nextDouble();
				op = keyboard.next();
				b = keyboard.nextDouble();

				switch (op) {
					case "+":
						c = a + b;
						break;
					case "-":
						c = a - b;
						break;
					case "*":
						c = a * b;
						break;
					case "/":
						c = a / b;
						break;
					default: {
						System.out.println("Undefined operator: '" + op + "'.");
						c = 0;
					}
				}

				System.out.println(c);

			} while (a != 0);

			System.out.println("Bye now.");
		}
		catch (InputMismatchException e)
		{
			System.out.println("WRONG INPUT!!!!");
		}
	}
}


    

Picture of the output

Assignment 70