Project #4

Code

      /*
jack newsom
period 5
program Calc
filename Calc
date completed 11/10/2015
*/

import java.util.Scanner;

public class Calc
{
    public static void main( String[] args )
    {
        Scanner bot = new Scanner(System.in);
        
        double a, b;
        String op;
        
        System.out.print("> ");
        a  = bot.nextDouble();
        op = bot.next();
        b  = bot.nextDouble();
        
        do {

                if ( op.equals("+") == true )
                {
                    System.out.println( addition(a,b));
                }
                else if ( op.equals("-") == true )
                {
                    System.out.println(subtraction(a,b));
                }
                else if ( op.equals("*") == true || op.equals("x") == true )
                {
                    System.out.println(multiplication(a,b));
                }
                else if ( op.equals("/") == true )
                {
                    System.out.println(division(a,b));
                }
                else if ( op.equals("^") == true )
                {
                    System.out.println(exponent(a,b));
                }
                else if ( op.equals("%") == true )
                {
                    System.out.println(remainder(a,b));
                }
                else
                {
                    System.out.println("Undefined operator"); 
                }
            
                System.out.print("> ");
                a  = bot.nextDouble();
                op = bot.next();
                b  = bot.nextDouble();
            
            } while ( a != 0 );

        
    }
    
    public static double addition ( double a, double b )
    {
        double c = a + b;
        
        return c;
    }
    
    public static double subtraction ( double a, double b )
    {
        double c = a - b;
        
        return c;
    }
    
    public static double multiplication ( double a, double b )
    {
        double c = a * b;
        
        return c;
    }
    
    public static double division ( double a, double b ) 
    {
        double c = a / b;
        
        return c;
    }
    
    public static double exponent ( double a, double b )
    {
        
        double exp = a;
        double c = a;
        
        
        for ( double test = 1; test < b; test = test + 1 )
        {
            c = c*exp;   
        }
        
        return c;
    }
    
    public static double remainder ( double a, double b )
    {
        double c = a % b; 
        
        return c;
    }
    
}
    

Picture of the output