For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2006 > java package - money









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author java package - money
java_nut

2006-10-30, 7:32 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com