Results 1 to 8 of 8

Thread: methods

  1. #1
    ooble is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default methods

    really really new to java and im scratching my head where im going wrong and not getting this to work.
    I have wrote an instance method that will perform an action if a previously declared variables value is true, if it is false it will not perform the action. Now i can only get it to perform the action if the variable is false and it does nothing when true.
    Java Code:
       
    public void cheer()
    {
       if(!happy)
       {
    
          this.performAction("cheer");
       }
    
    }
    happy is the variable where the true or false value is stored.
    Thanks for any pointers

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,253
    Rep Power
    19

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by ooble View Post
    Now i can only get it to perform the action if the variable is false and it does nothing when true.
    Java Code:
       
    public void cheer()
    {
       if([COLOR="red"]![/COLOR]happy)
       {
    
          this.performAction("cheer");
       }
    
    }
    Do you know, what the red thing in if statement does?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  4. #4
    ooble is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Yes it turns a true value to false and false to true which is why im getting nowhere with it.
    Think i have it
    Java Code:
    if(happy && happy)
    Seems to be doing what i need.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Have you tried it with only one happy variable? if (happy)

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    The easiest approach would be,
    Java Code:
    if (happy) {
    	// Do happy things
    } else {
    	// Do sad things
    }
    Hope that makes some sense,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,253
    Rep Power
    19

    Default

    Without code tags...

    if (happy) {
    ___
    } else {
    ___
    }

    db

  8. #8
    ooble is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Odd, i was sure i tried it with just one happy.
    Thanks all

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. All the methods
    By N00Bie in forum New To Java
    Replies: 5
    Last Post: 02-12-2011, 02:18 PM
  3. methods vs. non methods
    By Latanyar in forum New To Java
    Replies: 10
    Last Post: 10-11-2010, 11:46 PM
  4. Methods
    By soccer_kid_6 in forum New To Java
    Replies: 3
    Last Post: 03-02-2010, 12:14 AM
  5. Replies: 4
    Last Post: 04-03-2009, 06:36 AM

Posting Permissions

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