Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-13-2008, 08:40 PM
Member
 
Join Date: Jun 2008
Posts: 4
steve123 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-13-2008, 11:08 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
Have some fun with the newbie
Code:
public class Mover { public static boolean MoveTheWorld(int steps) { return (steps > 1)?((steps < 10)?true:false):false;// } }
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.

You have to to get any skills progress.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-14-2008, 12:14 AM
Member
 
Join Date: Jun 2008
Posts: 4
steve123 is on a distinguished road
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?.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-14-2008, 12:21 AM
Member
 
Join Date: Jun 2008
Posts: 4
steve123 is on a distinguished road
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?.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-14-2008, 01:12 AM
Member
 
Join Date: Jun 2008
Posts: 4
steve123 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-20-2008, 10:45 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
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:
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)) { //.............. }
I omitted a bunch of code, this will be too much but yes we can is the answer to what your questions pose.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a public void method from a class button supa_kali_frajilistik AWT / Swing 4 05-23-2008 03:05 PM
calling a public void method from a class button supa_kali_frajilistik AWT / Swing 1 05-21-2008 07:40 AM
Instantiation using an instance factory method Java Tip Java Tips 0 03-29-2008 02:35 PM
public method dirtycash New To Java 4 11-21-2007 09:29 PM
Instantiation using an instance factory method JavaBean Java Tips 0 09-26-2007 10:25 PM


All times are GMT +3. The time now is 02:49 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org