Valid operations are: +, -, *, /, nCr.
nCr is the choose (binomial) operator from combinatorics: n!/(k!(n-k)!).
All of the arithmetic operations should be carried out within a function:
Here are the specs:
Your program should be called RPNCalc.java.
It must have, at a minimum, the following methods/functions:
public static double sum(double a, double b) // a+b
public static double minus(double a, double b) // a – b
public static double times(double a,double b) // a*b
// a/b (division by 0 is not allowed.
// System prints Error and continues without the division).
public static double divide(double a, double b)
//nCr (which can only be done with integer parts of the numbers)
public static double nCr(double a, double b)
public static int factorial(int n) // n! (will help with nCr)
Rubric:
Program must compile. Otherwise you get 0 points, so test it before you send it in.
All functions and conventions respected: 35
Functions work correctly: 40
Calculator works correctly: 25 (asks for input in the order established. Also, see example).
Sample run (bold font indicates System output. Non-bold is user input)
Enter one of the valid operations: + – * / nCr
Enter q for the operation to quit the program.
X: 5
Y: 12
Op: *
60.0
Y: 7
Op: /
8.571428571428571
Y: 2
Op: +
10.571428571428571
Y: 1
Op: –
9.571428571428571
Y: 2
Op: nCr
36.0
Y: 0
Op: q
Your last result was: 36.0
And in an error, the relevant portion may look like this:
3
Y: 0
Op: /
Error, attempted a division by zero
3.0
Y:


0 comments