Assignemnt Project 4: Calculator
Code
/// Name: Cassie Rapp
/// Period: 6
/// Program Name: Calculator
/// File Name: CalcProj.java
/// Date Finished: 5/3/2016
import java.util.Scanner;
public class CalcProj {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int a, b, c;
String op;
System.out.println();
System.out.println( "Cassie's Calculator" );
System.out.println();
System.out.println( "Enter any basic expression below." );
System.out.println( "Enter \"quit\" instead of an operator to exit the calculator" );
System.out.println();
do {
System.out.print( "> " );
a = keyboard.nextInt();
op = keyboard.next();
b = keyboard.nextInt();
if ( op.equals("+") ) {
c = a + b;
System.out.println( c );
} else if ( op.equals("-") ) {
c = a - b;
System.out.println( c );
} else if ( op.equals("*") ) {
c = a * b;
System.out.println( c );
} else if ( op.equals("/") ) {
c = a / b;
System.out.println( c );
} else if ( op.equals("^") ) {
c = a;
for ( int i = b; i > 1; i-- ) {
c *= a;
}
System.out.println( c );
} else if ( op.equals("quit") ) {
System.out.println( "Farewell" );
} else {
System.out.println( "error" );
}
System.out.println();
} while ( !op.equals("quit") );
}
}
Picture of the output