Search:

Type: Posts; User: Norm

Search: Search took 0.11 seconds.

  1. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    I am Glad to hear you figured it out. I'll see you later for your next problem.
  2. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    No the code using the compareTo method. It needs to have a reference to the name in the Person in the Node and a reference to the name in the Person from the user.
  3. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    No. You need to change a class to add a method to it.
    The String class's compareTo method can be used to compare the name variables from two different instances of Node class/Person class. Your...
  4. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Does that compile? Does Node have a member named name? The code shows the only members of Node are a Person and a Node.


    The == operator tests if the two object references point to the same...
  5. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    The name is in the Person object and that is inside of a Node object. Something like this:
    nodeRef.personRef.name

    The user's passed name is in a Person object: public boolean insert(Person...
  6. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Yes, not in the Node class. p.name does not exist.
  7. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    The compiler can not find a declaration for name in the class Node.
    Where is the variable name defined? Is it in the Person class object inside of Node?


    Note: p is a confusing name for a Node...
  8. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    An empty method would not contain any processing code. At a minimum it could have a return statement that returned a value of the required type. No return needed for void.
    For int: return 0;
    for...
  9. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Is there any more processing to be done in the method AFTER value is set to false?
    If there is nothing more the method should do, it could immediately return false and not execute any more code in...
  10. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    boolean returnVal = true; // set initial value
    // here is some code that does some tests
    // if you want to return false, set returnVal = false;
    // when exiting the method: return...
  11. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Does that mean if the insert tries to add an existing entry, the code should return false?


    What is insert supposed to do? Why does it exit if the compare returns not equal?

    There could be a...
  12. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Look at the documentation for that method in the API doc: https://docs.oracle.com/javase/8/docs/api/index.html
    At the top of the page in the blue strip, click on the INDEX link. Then click on the...
  13. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    This code is trying to compare the contents of two different types of objects: Node and String

    int comparison = p.compareTo(name);

    I think the description of that code should be: compare...
  14. Replies
    28
    Views
    1,459

    [SOLVED] Re: Sorted list and compareTo method

    Do they do what you want them to do? Do you get the correct result?

    A suggestion: write a simple short program that calls the compareTo method 3 times:

    System.out.println("smaller " +...
Results 1 to 14 of 14