Results 21 to 34 of 34
Thread: help with arguments
- 01-27-2011, 02:09 AM #21
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
You're asking for a parameter aColour here, but you're never using it. And you don't need it. Take that parameter out of the method declaration, and call setColour() within setLastReceived() and setLastGiven().Java Code:/** * sets the colour to blue if LastReceived is true or red if Lastgiven is true */ public void setColour(OUColour aColour) { if (getLastReceived() == (true)) { aColour = OUColour.BLUE; } if (getLastGiven() == (true)) { aColour = OUColour.RED; } }
-Gary-
- 01-27-2011, 02:15 AM #22
OK so no GUI but you must be doing some sort of displaying. After you have changed the colour are you making another call to whatever method does the display?
- 01-27-2011, 02:15 AM #23
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
thanks 4 the reply babes, i did try that and it told me missing identifier as i still had OUColour in the (), when i took it out my statements were no longer right.....or some error message like that.
Thats what made sense to me at first. but with my specs it told me i have 2 take a single argument of type of OUColour....
i feel like im going round in circles :(
- 01-27-2011, 02:17 AM #24
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
hey junky
yh but i dont have to call it.Its built into a gui that theyve given us to test. So i input
MoneyFrog mf1 = new MoneyFrog("dave", "2345", 500);
MoneyFrog mf2 = new MoneyFrog("dave", "2345", 900);
mf1.share(mf2);
and then open the graphics display and see my two green frogs :P
- 01-27-2011, 02:31 AM #25
- 01-27-2011, 02:35 AM #26
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
Its a bit hard 2 post all but the relevent ones....
Write a public instance method setColour() method in MoneyFrog which takes a single argument of type...OUColour and returns no answer. The method should set the colour of the reciever to the value of the argument if the values of the boolean instance variables are appropriate. eg. setColour(OUColour.BLUE) sets the receiver to blue if its boolean var lastReceived is true under any other circumstances setColour() should have no effect
wow :)
- 01-27-2011, 02:38 AM #27
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
I also think the reason for the argument is so it overrides (i think thats the right term) the orginal method which must be in a really high up superclass.....but thats just me i may be wrong still learning :P
- 01-27-2011, 02:45 AM #28
So follow the instructions exactly (well almost, ignore the example using OUColour.BLUE).
Write a method called setColour. Done.
Returns no answer (void). Done
Has a single parameter of type OUColour. Done
Now the tricky part.
Set the receiver to the colour passed as a parameter (not just BLUE). Not done. Any colour can be passed and it must be set to that colour. Your code is hard coded to always set it to blue.
Where in the specs does it say to set it to RED if lastGiven is true? get rid of that bit.
- 01-27-2011, 02:47 AM #29
Another problem I just noticed. You are setting the parameter aColour to BLUE and not the instance variable.
- 01-27-2011, 02:51 AM #30
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
soz musta missed that bit darlin....similary setColour(OUColour.RED sets the reciever to red if its boolean var last given is true...........
set the receiver to the colour passed. i tried that but once again im stuck on the reciever side...does that mean then...
that OUColour.BLUE sould be OUColour.aColour......? or this.OUColour i tried that too
- 01-27-2011, 02:53 AM #31
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
ye i would agree with u its only a local var but they told us to declare the instance vars at the beginning and didnt mention aColour i thought this and within the spec it doesnt tell you to assign an instance var like the others.
Can i do it without it?
- 01-27-2011, 02:58 AM #32
It is all a bit vague and confusing to me but if I understand correctly...
Java Code:public void setColour(OUColour aColour) { if (lastReceived) { // access instance variables directly instanceVariable = aColour; // obviously change instanceVariable to whatever the variable is actually called // or maybe even super.setColour(aColour) // but I am still unfamiliar with your assignment } if (lastGiven) { instanceVariable = aColour; } }
- 01-27-2011, 03:08 AM #33
Member
- Join Date
- Jan 2011
- Posts
- 17
- Rep Power
- 0
yh dont make sense to me either the only instance var i have are
/* instance variables */
private boolean lastReceived;
private boolean lastGiven;
private Account account;
and none of them are ok to use.
The super doesnt work because its still not called anywhere or change the colours.
Think im going to have to leave it and see where i went wrong.
Ive tried my best...plus ur help :P
thats all i can do
thanks ever so much though
i always feel alone learnin this stuff all my friends hate computers and love shoes...not that i dont :) (love shoes)
thanks again
- 01-27-2011, 03:10 AM #34
Similar Threads
-
Arguments
By maya700 in forum New To JavaReplies: 12Last Post: 02-01-2011, 05:57 PM -
Sorting objects with 2 strings arguments and 2 int arguments
By tirwit in forum New To JavaReplies: 8Last Post: 09-23-2010, 12:07 AM -
Default Arguments
By Mark Robert in forum New To JavaReplies: 6Last Post: 08-17-2010, 02:56 PM -
How do i do a method twice, but with different arguments?
By Meta in forum New To JavaReplies: 6Last Post: 04-05-2010, 09:58 PM -
repetition of 'arguments'(?)
By Igor in forum New To JavaReplies: 3Last Post: 12-13-2007, 10:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks