Assignemnt #p4

Code

          /// Name: Holden Ganch
          /// Period: 7
          /// Program Name:  Third Project
          /// File Name: Longer.java
          /// Date Finished: 3/16/2015


    
  import java.util.Scanner;

public class P4
{
	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 = multi(a,b);
            else if ( op.equals("/"))
                c = divide(a,b);
            else if ( op.equals("-"))
                c = subtract(a,b);
            else if (op.equals("%"))
                c = modulus(a,b);
            else if (op.equals("!"))
                c = fact(a);
            else if (op.equals("^"))
                c = exp(a,b);
			else
			{
				System.out.println("Undefined operator: '" + op + "'.");
				c = 0;
			}
            if ( a != 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 multi ( 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 subtract (double a, double b)
    {
        double total;
        total = a - b;
        return total;
    }
    public static double modulus ( double a, double b)
    {
        double total;
        total = a % b;
        return total;
    }
    public static double fact ( double a)
    {
        double total = a;
        double x = a - 1;
        for( double n = x; n > 0; n--)
        {
            total = total * n;
        }
        return total;
    }
    public static double exp( double a, double b)
    {
        double total = a;
        for (int n = 1; n< b; n++)
        {
            total = total * a;
        }
        return total;
    }
    
        
    
}




    

Picture of the output

Assignment p4