Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java boolean

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Java boolean

    How can I make it so the toEq() method compare if the method boolean equals(Object b) results in false or true and then assign a string? Thanks

        public boolean equals(Object b)
        {
            if(!(b instanceof Rectangle3))
            return false;
     
            Rectangle3 t = (Rectangle3)b;
            return t.getLength() == getLength() && t.getWidth() == getWidth() && height == height;
        }
     
        public String toEq()
        {
            if(equals() == false)
            {
                return "same";
            }
            else
            {
                return "not the";
            }
        }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,349
    Thanks
    49
    Thanked 2,203 Times in 2,176 Posts

    Default Re: Java boolean

    You need to pass an arg to the method that it can pass to the equals() method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: February 17th, 2012, 06:05 PM
  2. Operator || cannot be applied to java.lang.String, boolean
    By djl1990 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2011, 06:00 PM
  3. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 09:56 AM
  4. Help with Java MenuItem and Boolean
    By Just Incredible in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 8th, 2010, 03:15 PM
  5. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 10:15 AM