Results 1 to 6 of 6
Thread: public instance method
- 06-13-2008, 06:40 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
public instance method
Hi i am a newbie to coding in java and would very much appreciate some help with an assignment question.Ok first off i dont want someone to answer the question for me (as i genuinely would like to learn how to code) but would appreciate an example i could work from if possible?.
The question is asking for a public instance method that returns a true/false value for a given number of moves using a type int argument.Eg below 1 is false above 10 false and 1-10 being true.
Any example of how i would code such a method would help me in answering my assignment question and also in understanding how to go about writing such code.
Thank you in advance.
- 06-13-2008, 09:08 PM #2
Have some fun with the newbie
How about asking some questions about what I put up?....They are going to laugh at me so I am paying the price, you can too.Java Code:public class Mover { public static boolean MoveTheWorld(int steps) { return (steps > 1)?((steps < 10)?true:false):false;// } }
You have to to get any skills progress.
- 06-13-2008, 10:14 PM #3
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Hi Nic
Thank you for taking the time to reply to my post this has helped me such a lot,the example you provided shows me exactley what i needed to know.I appreciate this very much my friend.
I do have a question though, can i use the same principle for a public instance method that takes a string argument rather than an int?.
i have noticed there are 2 variables in the int argument ie less than and greater than if i wanted to write code using a string argument using particular types of movements to return a true/false result could i use the same or simillar code or is it totally different?.
- 06-13-2008, 10:21 PM #4
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Hmm i am presuming that my assignment q is asking for an instance of a class method when it is asking for an instance method?.
- 06-13-2008, 11:12 PM #5
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
This example you posted is far more advanced than whats in my learning material,i have been doing some reading and cannot find reference to the boolean operators you have used like the ? and : . My learning material refers to using the " if " statement and the operator ==, which is what has confused me as i know there has to be the operators < and > to fix the boundry.
- 06-20-2008, 08:45 PM #6
My uplink has not been uplinking, sorry for the delay. At your skills, there is several things that can be done: In short, if you can declare it you can pass it to a method. Public Instance methods are just methods for now, all that access modifier stuff and so on is just to keep you with something to study. I just put everything in one file and do not bother with all the OO stuff until I have enough that it has to be disentangled to make it work.
At that point, I study OO.
The code looks the same for true / false and so on. Just be careful as String compare will get you ahead of where you are at right now.
The == operator will fail unless it is only used on what is called primitive types. If you can make something a class, then we use what is called equals();
I posted the ternary operator, which you found, to test your willingness to look something up. We do ( in general ) do it like this:
I omitted a bunch of code, this will be too much but yes we can is the answer to what your questions pose.Java Code:// Skipped a bunch of stuff for get-going class One {} class Two {} class Three{} class Four { public static void main(.... One one = new One(); Two two = new Two(); Three three = new Three(); boolean anEqualsTest(One aOneClassInstace) { if two.equals(aOneClassInstace) { return true; } else { if(three.equals(aOneClassInstace)) { //.............. }
Similar Threads
-
calling a public void method from a class button
By supa_kali_frajilistik in forum AWT / SwingReplies: 4Last Post: 05-23-2008, 01:05 PM -
calling a public void method from a class button
By supa_kali_frajilistik in forum AWT / SwingReplies: 1Last Post: 05-21-2008, 05:40 AM -
Instantiation using an instance factory method
By Java Tip in forum Java TipReplies: 0Last Post: 03-29-2008, 12:35 PM -
public method
By dirtycash in forum New To JavaReplies: 4Last Post: 11-21-2007, 07:29 PM -
Instantiation using an instance factory method
By JavaBean in forum Java TipReplies: 0Last Post: 09-26-2007, 08:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks