-
what error do you get with a compareTo method?
--what would happen if you had an input of java MyDriver "candy apple red" candy apple red ?
public class MyDriver {
public static void main(String[] args) {
Comparable t1 = new Truffle(args[0]);
Comparable t2 = new MooseMunch(args[1]);
if (t1.compareTo(t2.toString()) < 0)
System.out.println(t1.toString());
else if (t1.compareTo(t2.toString()) > 0)
System.out.println(t2.toString());
else
System.out.println("1st = " + t1.toString() +
" : 2nd = " + t2.toString());
} // main
} // MyDriver
-
How can we know as long as you have not posted the code for Truffle
and MooseMunch ?
eschew obfuscation
-
here is the truffle class...
Public class Truffle implements Comparable {
private String flavor;
public Truffle (String flavor) {
this.flavor = flavor;
}
public int compareTo(Object o) {
return this.flavor.compareTo((String) o);
}
public String toString() {
return this.flavor;
}
} // Truffle
-
her is the moosemunch class...
public class MooseMunch implements Comparable {
private String color;
public MooseMunch (String color) {
this.color = color;
}
public int compareTo(Object o) {
return this.color.compareTo((String) o);
}
public String toString() {
return this.color;
}
} // MooseMunch
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks