Project #4 and Calculator

Code

    
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Project Calculator
/// File Name: Project4.java
/// Date Finished: 4/26/2016

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 = factorial(a);
            else if ( op.equals("%") )
                c = modulus(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 factorial( double a)
    {
        double total = a;
        double z = a - 1;
        for ( double x = z; x > 0; x-- )
            total = total * x;
        return total;
    }
    public static double modulus( 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

Assignment 8