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

[4260 byte] By [IneedHelpPleasea] at [2007-9-29 15:37:54]
# 1

INeedHelpPlease,

DON'T CROSS-POST!

Send your dumb-*ss questions to just ONE forum if you must. It's bad enought to have to read this drivel in the New To Java Techology forum without having to see it everywhere else.

Posting the same question to multiple forums will NOT increase your chances of getting a good answer. It'll only *iss people off. Don't do it anymore. It's considered rude. - MOD

duffymoa at 2007-7-15 13:34:34 > top of Java-index,Other Topics,Algorithms...
# 2

I think you should do it in diffrent way .

using a String will be easy .

When the user type the number then just concat it to the string display and

when you want to calculate then convert it to double using the class Double

double My_Double = double.parseDouble(display)

Nightman150a at 2007-7-15 13:34:35 > top of Java-index,Other Topics,Algorithms...