Question: I am writing an order list program in Java and there is a compareTo() method requirement, instructions below. Within this method I need to have
I am writing an order list program in Java and there is a compareTo() method requirement, instructions below. Within this method I need to have 2 parameters evaluated - one is a String and the other is an integer. Ideally, I need both parameters to uniquely identify one "thing" from the other and "street" alone will not do that - also need "number" to make it a unique object. I am getting an error message from the compiler that states "The operator && is undefined for the argument type(s) int, boolean". My code is pasted below.
public class Property { private String street; private int number; private boolean occupied; public Property(String street, int number, boolean occupied) { this.street=street; this.number=number; this.occupied=occupied; } .................
public int compareTo(Property p) { return this.getStreet().compareToIgnoreCase(p.getStreet())&&this.getNumber()==(p.getNumber());
Below are the specific instruction for this section of the program.
Implement the Comparable interface and the compareTo() method for your Thing. compareTo() returns
- a negative number when the invoking object's search key is less than the parameter's search key
- 0 when the two search keys are equal
- a positive number when the invoking object's search key is greater than the parameter's search key
- For example, "ant".compareTo("bat") will return a negative number.
- Your compareTo() method must compare two Things.
- Note that the comparison of String attributes should be case insensitive. For example, MATH, math and Math must match each other.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
