Results 21 to 33 of 33
- 06-20-2011, 05:56 AM #21
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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
but under the Person class it says I can not return on a class that is void.Java Code:String nameDollars = (lastName+" has "+wealth+" dollars.");
- 06-20-2011, 06:04 AM #22
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 ....Java Code:public void methodName
- 06-20-2011, 06:07 AM #23
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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.
- 06-20-2011, 06:12 AM #24
Ahhhhh. Of course now I see the problem.
- 06-20-2011, 06:13 AM #25
Oh wait. No I don't because I am not psychic.
- 06-20-2011, 06:15 AM #26
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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.
- 06-20-2011, 06:25 AM #27
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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; }
- 06-20-2011, 07:00 AM #28
I bet it is returning the String, you just don't do anything with it.
That is an assignment and not a comparison. Besides when dealing with booleans it is better to use:Java Code:if(mentalState = true)
Java Code:boolean flag = true; if(flag) if(! flag)
- 06-20-2011, 07:14 AM #29
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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
- 06-20-2011, 07:17 AM #30
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.
- 06-20-2011, 07:24 AM #31
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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.
- 06-20-2011, 07:31 AM #32
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
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.
- 06-20-2011, 08:46 AM #33
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
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.
Similar Threads
-
How to code a program to send messages to a chat program?
By josh2992 in forum New To JavaReplies: 2Last Post: 04-02-2011, 12:57 PM -
tricky initial value problem
By Black_Eye in forum New To JavaReplies: 4Last Post: 10-19-2010, 09:02 AM -
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
Tricky but very interesting problem
By ravjot28 in forum New To JavaReplies: 4Last Post: 06-26-2008, 01:43 PM -
tricky indexOf implementation -- Help!!
By definewebsites in forum New To JavaReplies: 3Last Post: 12-10-2007, 12:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks