good evening guys,
i am finding a piece of work extremely tough going at the moment and
wondered if i could get any hints/help on where im going wrong. i am
aiming to produce a package (money.java) which could be used in order
to produce arithmetic calculations on sums of money.
The code i have at the moment is:
MONEY.JAVA:
package java;
public class money
{
private int data1, data2;
public money()
{
data1=0;
data2=0;
}
public money(int value1, int value 2)
{
data1 = value1;
data2 = value2;
}
public void addMoney(int value1, int value2)
{
return value1 + value2;
}
public void subtractMoney(int value1, int value2)
{
return value1 - value2;
}
public void divideMoney(int value1, int value2)
{
return value1 / value2;
}
public void multiplyMoney(int value1, int value2)
{
return value1 * value2;
}
}
MONEYTEST.JAVA
import java.money;
public class MoneyTest
{
public static void main(String [] args)
{
money p = new money(10,20);
System.out.println("The total is " + p.addMoney());
}
}
I think i may need a 'toString' method? and also, is there any way of
covering errors? im sorry if these problems are trivial. I have various
books, but can't seem to use them in this case.
Thank you for any feedback.
Jess
Chris Smith - 27 Oct 2006 00:04 GMT
> i am finding a piece of work extremely tough going at the moment and
> wondered if i could get any hints/help on where im going wrong.
For one thing, a return type of "void" means that a method isn't going
to return a result. You can't put a return statement that specifies a
return value into a "void" method. If you want the method to have a
result, change "void" to an appropriate data type.
That should get you started, anyway.

Signature
Chris Smith