DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Posts
    6

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    How can we know as long as you have not posted the code for Truffle
    and MooseMunch ?
    eschew obfuscation

  3. #3
    Join Date
    Mar 2005
    Posts
    6

    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

  4. #4
    Join Date
    Mar 2005
    Posts
    6

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links