Assignemnt #107
Code
//colin hinton
//5th period
//Calc.java
//3/9/2016
import java.util.Scanner;
public class Calc
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double a, b, c;
String op;
do
{
System.out.print("> ");
a = keyboard.nextDouble();
op = keyboard.next();
b = keyboard.nextDouble();
if ( op.equals("+") )
System.out.println(Add(a,b));
else if (op.equals("-"))
System.out.println(Sub(a,b));
else if (op.equals("*"))
System.out.println(Mul(a,b));
else if (op.equals("/"))
System.out.println(Div(a,b));
else
{
System.out.println("Undefined operator: '" + op + "'.");
}
} while ( a != 0 );
}
public static Double Add(Double c, Double d)
{
Double e = c + d;
return e;
}
public static Double Sub(Double c, Double d)
{
Double e = c - d;
return e;
}
public static Double Mul(Double c, Double d)
{
Double e = c*d;
return e;
}
public static Double Div(Double c, Double d)
{
Double e = c/d;
return e;
}
}
Picture of the output