Project 4
Code
///Name: Cody Swain
///Period: 6
///Project Name: project4
///File Name: project4.java
///Date: 5/9/16
import java.util.Scanner;
public class project4
{
public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
double a, b, c=0.0;
String op;
System.out.println("Calculator Program" );
System.out.println("Enter a calculation. ");
do
{
System.out.print("> ");
a = kb.nextDouble();
op = kb.next();
b = kb.nextDouble();
if (op.equals("+"))
c = addition(a, b);
else if (op.equals("*"))
c = multiplication(a, b);
else if (op.equals("-"))
c = subtraction(a, b);
else if (op.equals("/"))
c = division(a, b);
else if (op.equals("^"))
c = exponent(a, b);
else
System.out.println("Error");
System.out.println( a + op + b + " equals " + c );
}
while (a != 0);
}
public static double addition( double a, double b )
{
double sum = a+b;
return sum;
}
public static double multiplication( double a, double b )
{
double sum = a*b;
return sum;
}
public static double subtraction( double a, double b )
{
double sum = a-b;
return sum;
}
public static double division( double a, double b )
{
double sum = a/b;
return sum;
}
public static double exponent( double a, double b )
{
double sum = Math.pow(a, b);
return sum;
}
}
Picture of the output