Results 1 to 6 of 6
  1. #1
    steve123 is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Lightbulb 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.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default Have some fun with the newbie

    Java 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.

  3. #3
    steve123 is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    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?.

  4. #4
    steve123 is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    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?.

  5. #5
    steve123 is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    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.

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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:
    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))
            {
                  //..............
    }
    I omitted a bunch of code, this will be too much but yes we can is the answer to what your questions pose.

Similar Threads

  1. calling a public void method from a class button
    By supa_kali_frajilistik in forum AWT / Swing
    Replies: 4
    Last Post: 05-23-2008, 02:05 PM
  2. calling a public void method from a class button
    By supa_kali_frajilistik in forum AWT / Swing
    Replies: 1
    Last Post: 05-21-2008, 06:40 AM
  3. Instantiation using an instance factory method
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-29-2008, 01:35 PM
  4. public method
    By dirtycash in forum New To Java
    Replies: 4
    Last Post: 11-21-2007, 08:29 PM
  5. Instantiation using an instance factory method
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:25 PM

Posting Permissions

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