@SuppressWarnings("unchecked")

class MyBooks implements Comparable{

    static final CompareLastName c1 = new CompareLastName();
    static final CompareFirstName c2 = new CompareFirstName();
    static final CompareTitle   c3 = new CompareTitle();
    static final ComparePrice c4 = new ComparePrice();
    static final CompareISBN  c5 = new CompareISBN();
    static final CompareDate c6 = new CompareDate();

    private String lastname, firstname, title, price, isbn, date;

    public MyBooks(String ln, String fn, String te, String pe, String in, String de) {

        lastname = ln;
        firstname = fn;
        title = te;
        price = pe;
        isbn = in;
        date = de;

    }// end MyBooks constructor


    public int compareTo (MyBooks b1, MyBooks b2) {  

        return 1; 
    } // end method compareTo required by Comparable interface

    public String toString () {
       return "\t" + lastname + "\t" + firstname + "\t" + title + "\t" + price + "\t" + isbn + "\t" + date;
    } // end method toString

    static class CompareLastName implements Comparator <MyBooks>{
           public int compare (MyBooks b1, MyBooks b2) {
                if((b1.lastname).compareTo(b2.lastname) > 0)
                    return 1;
                else
                    return 0;
          } // end compare
        } // end CompareLastName[ICODE][/ICODE] class

    static class CompareFirstName implements Comparator <MyBooks>{
       public int compare (MyBooks b1, MyBooks b2) {
            if((b1.firstname).compareTo(b2.firstname) > 0)
                return 1;
            else
                return 0;
      } // end compare
    } // end CompareFirstName class

    static class CompareTitle implements Comparator <MyBooks>{
        public int compare (MyBooks b1, MyBooks b2) {
            if(b1.title.compareTo(b2.title) > 0)
                return 1;
            else
                return 0;
      } // end compare
    } // end CompareTitle class

    static class ComparePrice implements Comparator <MyBooks>{
       public int compare (MyBooks b1, MyBooks b2) {
            if(b1.price.compareTo(b2.price) > 0)
                return 1;
            else
                return 0;
      } // end compare
    } // end ComparePrice class

    static class CompareISBN implements Comparator <MyBooks>{
       public int compare (MyBooks b1, MyBooks b2) {
            if(b1.isbn.compareTo(b2.isbn) > 0)
                return 1;
            else
                return 0;
      } // end compare
    } // end CompareISBN class

    static class CompareDate implements Comparator <MyBooks>{
       public int compare (MyBooks b1, MyBooks b2) {
            if(b1.isbn.compareTo(b2.isbn) > 0)
                return 1;
            else
                return 0;
      } // end compare
   } // end CompareDate class

}//end MyBooks class

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Need Help with Comparable/Comparator.

Good for you. I, however, have no idea what that needed help might be, since you didn't say/ask.

Oh sorry, just have a problem with the following line and can't seem to figure out:

"class MyBooks implements Comparable{"

This article has been dead for over six months. Start a new discussion instead.