Published using Google Docs
Methods 4 Calculator
Updated automatically every 5 minutes

Methods 4 Calculator

Note: This assignment is designed to focus you on RETURN VALUES.  Therefore it is a bit arbitrary in how I ask you to flow the numbers.

Create a new file called Assign4_Calculator.java.  

You are to write a looping calculator program that asks the user for a math operation (+,-,*,/, power) or the word exit.  It then calls a method that has been written for each operation.  It keeps a running total back in the Run function. (NOTE: Power function is quite hard and is only worth 10%. Consider skipping it if short of time.)

User’s View

Welcome to the calculator.

What is your starting number?

        7

What math operation do you want ( +, -, *, /, power, exit )         

        *

What is your next number?

        3

Your total is now 21.

What math operation do you want ( +, -, *, /, power, exit )         

        +

What is your next number?

        8

Your total is now 29

What math operation do you want ( +, -, *, /, power, exit )          

power

What is the exponent?

        3

Your total is now 24389

Super Important Hint of the Century:  

Your method calls must outlook like this:          firstnum = add(firstnum);

Your variable name can be different but you must save the result of the method back into the original number so it is updated for the next loop.

Methods required for 90%:

Final 10% - Add a POWER function

 

Hints for the Power Function:

public static double power(double firstNum){

double exponent - ask and scan for this number.

double newTotal = 1;       //create a new variable and set to ONE.

For loop(){

        Multiply newTotal by firstNum

}

Return newTotal

Procedural Programming

By S. Couprie, 2021