0

If any one can help me please to answer this questions please:

  1. What is the difference between this.dollars and otherMoney.getDollars()
    2.- What the return statement of this method is returning.
    3.- How this method would be called from the main and give an example
    Thank you in advanced.

    // instance methods

    public Money addMoney( Money otherMoney ) {

    int newd = dollars + otherMoney.getDollars();
    int newc = cents + otherMoney.getCents();

    return new Money( newd, newc );

    }

    public Money subtractMoney( Money otherMoney ) {

    int newd = dollars - otherMoney.getDollars();
    int newc = cents - otherMoney.getCents();

    return new Money( newd, newc );
    }

3
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by toldav
Featured Replies
  • 1

    Why I have a feeling that this is your homework ;) anw heres a semi-answer ... 1 . the diff btw this.dollars and otherMoney.getDollars(): this.variable means refers to the variable in the current class where this.variable appears. getDollars() is a function for the composite otherMoney which is also of type … Read More

  • Thanks a lot. I'm new to java this is not really a home work. I did not understand the code, I always get confused by instance method, variables object of the class. That's all my confusion the more I read there always somthing to understand. for instance this 3 variables: … Read More

  • 1
    IIM 163   3 Years Ago

    >1- Circle myCircle1; >this is an instance variable of an object correct It is a reference variable.I think so you are a bit confused about reference and instance variable.Read [this](http://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html) >this assign myCircle3 to myCircle2 actually it is reverse.Assigning myCircle2 to myCircle3 Read More

1

Why I have a feeling that this is your homework ;)
anw heres a semi-answer ...
1 . the diff btw this.dollars and otherMoney.getDollars():
this.variable means refers to the variable in the current class where this.variable appears.
getDollars() is a function for the composite otherMoney which is also of type Money

2 . int newd = dollars + otherMoney.getDollars();
this means that getDollars() returns an Int

3 . this method can be called from the main by creating a new object of type Money

1

Thanks a lot. I'm new to java this is not really a home work. I did not understand the code, I always get confused by instance method, variables object of the class. That's all my confusion the more I read there always somthing to understand.
for instance this 3 variables:
1- Circle myCircle1;
this is an instance variable of an object correct
2- Circle myCircle2 = new Circle();
this declare a variable and and make a circle an object correct
3- Circle myCircle3 = myCircle2;
this assign myCircle3 to myCircle2
Please clarify if I'm wrong..!!
Thank you for your input

1

1- Circle myCircle1;
this is an instance variable of an object correct

It is a reference variable.I think so you are a bit confused about reference and instance variable.Read this

this assign myCircle3 to myCircle2

actually it is reverse.Assigning myCircle2 to myCircle3

Edited by IIM

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.