Results 1 to 20 of 20
  1. #1
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default Simple Help please!

    Hi, so just a quick one.
    Say you have two classes:

    Savings and Debt

    Savings has a contructor name like:
    public Savings (String name, String type, double anAmount)

    Debt has a constructor name like:
    public Debt (String name, String type, double anAmount)

    So the question i'm asking is how can you write a public instance method which has two arguments, for example savingsToDebt (String name, double anAmount) which take the String name and double anAmount from the Savings constructor method?

    So the end result would be that Debt has taken from Savings.

    If that didnt make any sence please let me know!

    Any help would be really cool, just a little info on how to do this would really help me out.

    Thank you!

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The constructor is not a method, it's a constructor, and it is used to set the state of some class. You create an object of some class by using the constructor. Once you have an object created you can apply methods on the object. Is your goal to change a savings object to a debt object? What do your class implementations look like so far?


    Edit: the constructor creates an object with the state set appropriately.
    Last edited by sunde887; 06-01-2011 at 07:09 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Is it possible to send the file to you as its quite a big picture that I would be telling here! Better if you just see it! It is in Blue J though (I know thats not the best one but that what I have to use as the course im on uses it!)
    Last edited by tdman; 06-01-2011 at 07:18 AM.

  5. #5
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Cool

    Quote Originally Posted by tdman View Post
    Ok its quite a big thing altogether...
    Your problem statement doesn't support this.

    Quote Originally Posted by tdman View Post
    do you guys have BlueJ ?
    It doesn't really matters.

    Just show us your efforts,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  6. #6
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Ok thank you guys sorry for being dumb!
    Last edited by tdman; 06-01-2011 at 11:01 PM.

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Please use code tags
    [code]
    YOUR CODE HERE
    [/code]

  8. #8
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Cool

    So whats the big deal?

    Write a plain method and pass on two arguments, one MoneyFrog instance and other double type. You have already made methods that take various arguments. I don't understand what is holding you back from doing this?

    By the way, I didn't understand this,

    The method should first attempt to transfer anAmount from the method should then cause the receiver to gloat in order to indicate that the robbery was successful.
    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  9. #9
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Hi, so how do you do it? How do I do that last bit? Things I do dont work! What would you type there?

    with that bit you said you didn't understand, once the robbery has taken place, the receiver will gloat (make a little noise like a croak) as if to laugh that he did it. (an animation for this has already been set.)


    Kind regards

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by tdman View Post
    Things I do dont work!
    Hey. I tried starting my car but it wouldn't work. Can you fix it?

  11. #11
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    yep, whats your make/modal ? Whats your entire history of the vehicle? Has it had any accidents? How much did it cost?

    thank you for that great answer there, this is such a helpful place... the clue is in the title... new to java .... so please dont ridicule me for not being as good as you guys... I am a beginner and yes the answer probably is in front of me but if I dont realise it then why would I ask!!!

  12. #12
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Cool

    Quote Originally Posted by Junky View Post
    Hey. I tried starting my car but it wouldn't work. Can you fix it?
    OP, I hope you got the indirect meaning behind this. Show us the things you did that didn't work.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by tdman View Post
    yep, whats your make/modal ? Whats your entire history of the vehicle? Has it had any accidents? How much did it cost?
    Exactly, you needed more information. Well guess what?

  14. #14
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Since you are passing an object into the method you can then use methods on that object. Are there any methods from the passed in object that allow you to change it?

    Java Code:
    public void robMoneyFrog(MoneyFrog victim, double amount){
      do something to change victim here
    }

  15. #15
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Ok sorry guys I am way slow on the mark today

    I tried things like:
    Java Code:
    public void robMoneyFrog (String victom, double anAmount)
    {
    MoneyFrog.holder = victom;
    or
    MoneyFrog.holderName = victom;
    or
    this.holder = victom;
    or 
    this.holderName = victom;
    Where the first part didnt work I havent even tried the double part.

    I'm sorry for that reply Junky, I am in a bit of a stupid panic over this and i'm not thinking straight!

  16. #16
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Cool

    Type of victim is supposed to be MoneyFrog NOT String.

    See above what Sunde has shown. Thats the way.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  17. #17
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I believe what is confusing you is that you seem to think the method should assign the money frog to something.

    The money frog is an already creates object being passed into this method. This method is also being called upon an already created robber frog. The calling of this method will look similar to this
    Java Code:
    MoneyFrog mf = ...;
    RobberFrog rf = ...; //the ... Is the construction, I left it out due to laziness
    rf.robMoneyFrog(mf, 100.00);
    after this, if the robbery succeeded, the state of the money frog and robber frog should change.

  18. #18
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Hi Sunde, the:
    Java Code:
    public void robMoneyFrog(MoneyFrog victim, double amount){
      do something to change victim here
    }
    seems right, but I just cant work out what to put in the 'do something to change victim here' part. I just need to to transfer 'anAmount' from 'account' victim (which is basicly MoneyFrog) and if successful then do the 'gloat();' method thats currently in MoneyFrog class.

    You put:
    Java Code:
    rf.robMoneyFrog(mf, 100,00);
    so how can that actually happen through the 'robMoneyFrog' method? What needs to go in that part? If I put
    Java Code:
    public void robMoneyFrog (MoneyFrog victim, double anAmount)
    {
    account.transfer(victim, 0.0);
    then this comes up:
    transfer(Account,double) in Account cannot be applied to (MoneyFrog,double)

  19. #19
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The error tells you whats wrong. The transfer method takes an account and you are giving it a money frog.
    Basically, you need to understand a few important things. The key thing is that both money frog, and robber frog have there own account.

    You want to access the accounts and remove/add the money to the correct accounts, and if successful, gloat.

  20. #20
    tdman is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    Sunde, im still feeling pretty dumb at the moment... can you give any clue as to what needs to go there?

    I just dont know how to do it! I hear what your saying but I cant implement it into the code
    I'm stupid...fact

Similar Threads

  1. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 01:44 AM
  2. 30 line simple gui, simple error, need help
    By cc11rocks in forum New To Java
    Replies: 6
    Last Post: 02-05-2011, 09:33 PM
  3. Very simple q
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 12-26-2009, 11:06 AM
  4. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 03:55 AM
  5. Replies: 2
    Last Post: 05-04-2008, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •