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: MyPorgramingLab Help

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MyPorgramingLab Help

    Below is the requirements and code. I am getting the error CODELAB ANALYSIS: LOGICAL ERROR(S)


    We think you might want to consider using: >
    Hints:
    • Correct solutions that use equals almost certainly also uses high
    • Correct solutions that use equals almost certainly also uses low


    Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int . Write an efficient static method , getWidgetMatch, that has two parameters . The first parameter is a reference to a Widget object . The second parameter is a potentially very large array of Widget objects that has been sorted in ascending order based on the Widget compareTo method . The getWidgetMatch searches for an element in the array that matches the first parameter on the basis of the equals method and returns true if found and false otherwise.

    public static boolean getWidgetMatch(Widget a, Widget[] b){
    int bot=0;
    int top=b.length-1;
    int x = 0;
    int y=0;
    while (bot >= top)
        {
            x = (top + bot/2);
     
            y = a.compareTo(b[x]);
     
            if (y==0) 
                    return true;
     
            if (y<0) 
                top=x;
     
            else 
                bot=x;
            return false;
            }
     
        return a.equals(b[x]);
    }

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: MyPorgramingLab Help

    Comments describing what you're doing with this code would be really nice. A few words that describe the codelab analysis comments would also be helpful to understand what the logical errors mean. Is it being robo graded or analyzed?

    When will bot >= top ?