MAJOR CALCULATOR

Code

/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Calculator
/// File Name: CalcProj.java
/// Date Finished: 4/15/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( "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( "Later Dude." );
                } else {
                    System.out.println( "***error***" );
                }
                
                System.out.println();
                
            } while ( !op.equals("quit") );
            
        }
    }
 
    

Code Output