Hi everyone,
I'm not sure how much you guys are allowed to help me with my assignment and its due tomorrow afternoon before class but I'm already expecting to get a zero on it but would still like to learn how to program and complete this program. I'm very weak with Java and programming in general but this class is required in my Networking/Security degree program. Any help would be greatly appreciated.
Here's the lab assignment:
This program is a simple "printing" calculator. It will accept input from
the user in the following form:
number operator
The number entered will be expected to be a float type.
The operator will be expected to be one of the following:
'E' or 'e' - Enter the number into the accumulator (this will destroy
the current value). This operator is used to set the
accumulator to a known value.
'A' or 'a' - Add the number to the current value in the accumulator
'S' or 's' - Subtract the number from the current value in the
accumulator
'M' or 'm' - Multiply the number times the current value in the
accumulator
'D' or 'd' - Divide the current value in the accumulator by the
number (do not divide the accumulator by zero)
'P' or 'p' - Raise the current value in the accumulator to the power
of the number, for this problem truncate the number to
its integer value. (negative numbers will not be allowed)
Do not use the "Math.pow()" method to solve this problem.
'T' or 't' - Terminate processing and print the final result. The
number accompanying this operator should be ignored.
The 't' or 'T' stop signal is entered by the user, the program will print
out the final value contained in the accumulator and terminate.
A sample session would be the following:
User inputs: Calculator outputs:
10.0 e = 10.0000
2 D = 5.0000
2 P = 25.0000
55.0 s = -30.0000
100.25 E = 100.2500
4 m = 401.0000
0 t = 401.0000
When the program starts the initial value for the accumulator is set to zero.
If the user gives an input that would result in an error if the operation
were to be attempted, an error message is printed and the current accumulator
value. This calculator handles three types of input errors:
1). if the user enters an invalid operator, the message is printed:
an invalid operator was entered - please reenter
2). if the user attempts to cause a divide by zero, the message
is printed:
attempt to divide by zero - please reenter
3). if the user attempts to raise the accumulator to a negative
power, the message is printed:
negative powers are not allowed - please reenter
__________________________________________________ __________________________________________________ ______
By looking at the requirements, here's how I would like to setup the program if I knew the proper syntax and all:
Step 1: Create Class called 'calculatorProgram'
Step 2: Use code that will allow UserInput after program executes (Our teacher forbids us to use Scanner, wants us to use InputStreamReader and BufferedReader)
Step 3: Create Variables:
*Fnum (It will be the Accumulating number)
*Ans (displayed after Fnum + operator)
*Operators: E, A, S, M, D, P, T (define their functions)
Step 4: -Tell user: "How to use the calculator and what letters to use for their function"
-Ask user to: "enter a number and an Operator function"
-
Step 5: Begin with a While loop( != 'T' || != 't'){} -I think that's how the loop should be formatted
Step 6: Design proper If/else and nested If/else statements for each operator and its function, be sure to use
nested if/else for invalid operators, divide by 0, and using negative powers.
***
Assuming I knew how to write Java this is how I would want to code my program. If anyone could help by giving me a small jump-start in the right direction it would be extremely helpful. I understand the concept or I/O and the purpose of Conditional statements just I have a hard time knowing how to place the variables in the right places and writing proper syntax.
Best regards,
Dan