Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Project 4
/// File Name: Project4.java
/// Date Finished: 3/8/2016 public class Project4
import java.util.Scanner;
public class Project4
{
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("+") )
{
c = add(a, b);
}
else if ( op.equals("-") )
{
c = subtract(a, b);
}
else if ( op.equals("*") )
{
c = multiply(a, b);
}
else if ( op.equals("/") )
{
c = divide(a, b);
}
else if ( op.equals("^") )
{
c = exponent(a, b);
}
else
{
System.out.println("Undefined operator: '" + op + "'.");
c = 0;
}
System.out.println(c);
} while ( a != 0 );
System.out.println("Bye, now.");
}
public static double add( double a, double b )
{
double total;
total = a + b;
return total;
}
public static double subtract( double a, double b)
{
double total;
total = a - b;
return total;
}
public static double multiply( double a, double b)
{
double total;
total = a * b;
return total;
}
public static double divide( double a, double b)
{
double total;
total = a / b;
return total;
}
public static double exponent( double a, double b)
{
double total = a;
for ( double x = 1; x < b; x++)
total = total * a;
return total;
}
}
Picture of the output