java help
Please help me...i cant seem to get the decimal function to work on my calculator..that is all i need tpo make my calculator work :
package calculators;
/**
* A simple Calculator
*/
public class SimpleCalculator {
static final String OPERATORS = "+-*/=";
public final static double ONE=1.0;
public final static double TWO =2.0;
public final static double THREE = 3.0;
public final static double FOUR = 4.0;
public final static double FIVE = 5.0;
public final static double SIX = 6.0;
public final static double SEVEN = 7.0;
public final static double EIGHT = 8.0;
public final static double NINE = 9.0;
public final static double ZERO = 0.0;
//Constuctor
/**
* Creates Instance of the class SimpleCalculator
*/
public SimpleCalculator (double display) {
this.display=display;
}
//QUERIES:
/**
* returns display
*/
public double getDisplay () {
return display;
}
/**
* returns if the number is a wholeNumber
*/
public boolean wholeNumber () {
display = 0;
return true;
}
//COMMANDS:
/**
* Adds one the the current value
*/
public void pressOne () {
if (wholeNumber=true)
display = ONE + display * 10;
else
(I need help here ...i need an algorithm to return it as a decimal..)
}
/**
* Adds two to the current value
*/
public void pressTwo () {
if (wholeNumber = true)
display = 2 + display * 10;
else
}
/**
* Adds three to the current value
*/
public void pressThree () {
display = 10.0 * display + THREE;
}
/**
* Adds four to the current value
*/
public void pressFour () {
display = 10.0 * display + FOUR;
}
/**
* Adds five to the current value
*/
public void pressFive () {
display = 10.0 * display + FIVE;
}
/**
* Adds six to the current value
*/
public void pressSix () {
display = 10.0 * display + SIX;
}
/**
* Adds seven to the current value
*/
public void pressSeven () {
display = 10.0 * display + SEVEN;
}
/**
* Adds eight to the current value
*/
public void pressEight () {
display = 10.0 * display + EIGHT;
}
/**
* Adds nine to the current value
*/
public void pressNine () {
display = 10.0 * display + NINE;
}
/**
* Adds zero to the current value
*/
public void pressZero () {
display = 10.0 * display + ZERO;
}
/**
* Adds dot to the current value
*/
public void pressDot () {
display = .0;
wholeNumber=false;
}
/**
* Adds function
*/
public void pressPlus () {
display= display + display;
}
/**
* subtract function
*/
public void pressMinus () {
display = display - display;
}
/**
* multiplies function
*/
public void pressStar () {
display = display * display;
}
/**
* divides function
*/
public void pressSlash () {
display = display / display;
}
/**
* sets value to zero
*/
public void clearCalculator () {
display = 0.0;
}
/**
* gets the answer from all the functions
*/
public void pressEquals () {
if (OPERATORS =="+")
display = operand + display;
else if (OPERATORS == "-")
display = display - operand;
else if (OPERATORS == "*")
display = display * operand;
else if (OPERATORS == "/")
display =display / operand;
}
//private components:
private double display;
private boolean wholePart;
private String operators;
private double operand;
private boolean wholeNumber;
WHEN I TEST IT I GET :
public TestSimpleCalculator () {
testInstance1 = new SimpleCalculator (5.1);
> java calculators.SimpleCalculatorTester
Expected: 51.1...Result : 52.0

