Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

java package - money

Thread view: 
java_nut - 26 Oct 2006 23:42 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.