Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
  1. #21
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    The way I see it, I have this fixed amount of money 50 bucks I can both spend and earn from that account. So when i spend I am subtracting from my balance and when I earn I add money. However since this program has seem to just kick me to the curve I just the output to look somewhat like the required. If you could help me with this new problem like how every time the testPerson class calls the x.says(); It's only returning the person's lastName when I need it to return this string
    Java Code:
    String nameDollars = (lastName+" has "+wealth+" dollars.");
    but under the Person class it says I can not return on a class that is void.

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

    Default

    Java Code:
    public void methodName
    The keyword void means that the method will return nothing. If you want the method to return something then you need to replace void with ....

  3. #23
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    Okay heres my next problem the person.says() call isn't returning anything and I don't know why.
    Last edited by CGHMN; 06-20-2011 at 06:15 AM.

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

    Default

    Ahhhhh. Of course now I see the problem.

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

    Default

    Oh wait. No I don't because I am not psychic.

  6. #26
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    Okay here's the problem the person.says() call isn't returning anything and I don't know why.

    it should be returning a String that says the person is happy and crap.

  7. #27
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    I have this:

    Java Code:
      public String says()
      {
        String imHappy = ("My name is "+lastName+" and I am doing great!"); 
    	 String better = ("My name is "+lastName+" and I could be better."); 
        if(mentalState = true)
    	 return imHappy;
    	 else
    	 return better;
    	 
      }

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

    Default

    I bet it is returning the String, you just don't do anything with it.
    Java Code:
    if(mentalState = true)
    That is an assignment and not a comparison. Besides when dealing with booleans it is better to use:
    Java Code:
    boolean flag = true;
    if(flag)
    if(! flag)

  9. #29
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    Well Junky I am almost done, the says method works the spend and earned method works, all I need is when the person has lets 7 dollars and spends 10 it shouldn't goto -3 it needs to default to 0. Should I make some if loop? like if(money<0) money = 0; else money= money;

    see heres was being bunk it's that Marie Osmond jerk, I never liked her.

    Im suppose to get the following

    Osmond has 500 dollars
    Osmond has 500 dollars
    Osmond has 0 dollars

    and Im getting

    Which is kind of stupid because the TestPerson is clearly spending money so the program is doing what it should. So I don't really care about that. However there should be a way to make a negative number just 0 so Im just going to test that if loop.

    Osmond has 510 dollars.
    Osmond has 410 dollars.
    Osmond has -19590 dollars.
    Marie currently has -19530 dollars

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

    Default

    There is no such thing as an if loop. Yes you will need some sort of if statement to prevent the amount going below zero.

  11. #31
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    Yep I got it to go

    Osmond has 0 dollars.
    Marie currently has 60 dollars


    With a while statement( not loop ) So I made this
    while(Money<0)
    {
    Money = 0;
    }

    And I think I am going to screw with the spend and earned methods to just jive when they take on a negative number.

  12. #32
    CGHMN is offline Member
    Join Date
    Jun 2011
    Posts
    40
    Rep Power
    0

    Default

    Ok I just wanted thank everybody for helping me especially you Junky. I have the program compile and running with all the required output. Thank you.

  13. #33
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    Quote Originally Posted by CGHMN View Post
    Yep I got it to go

    Osmond has 0 dollars.
    Marie currently has 60 dollars


    With a while statement( not loop ) So I made this
    while(Money<0)
    {
    Money = 0;
    }

    And I think I am going to screw with the spend and earned methods to just jive when they take on a negative number.
    I bet you this doesn't work as intended. I bet you it lets a person spend more money than they have and then sets the money variable to 0. Not a very profitable proposition for a bank. I think you would want to check to make sure the person has as much or more money as they intend to spend before you let them spend it. Which would most easily be accomplished with an if statement inside the spend method.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. tricky initial value problem
    By Black_Eye in forum New To Java
    Replies: 4
    Last Post: 10-19-2010, 09:02 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Tricky but very interesting problem
    By ravjot28 in forum New To Java
    Replies: 4
    Last Post: 06-26-2008, 01:43 PM
  5. tricky indexOf implementation -- Help!!
    By definewebsites in forum New To Java
    Replies: 3
    Last Post: 12-10-2007, 12:48 AM

Posting Permissions

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