It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Arrange Data by Lowest First

Arrange Data by Lowest First

Postby coops on Sun Mar 11, 2007 9:41 am

Hi, I am developing a little program for myself and I have come to a problem.. I have been using an RecordList to store and arrange my data, this has been working until now I need to sort out numerical data. I want to sort the data so the lowest amount is first. The code I am using is:
Code:
Code: Select all

  public Record(String n, String s, String f, String ty, String ti,String  stBreakFast, String stDinner, String stAfternoon, String stTea, String stEvening){
    name = n;
    start = s;
    finish = f;
    type = ty;
    till = ti;
    sBreakFast = stBreakFast;
    sDinner = stDinner;
    sAfternoon = stAfternoon;
    sTea = stTea;
    sEvening = stEvening;

   
    keys = new String[5];
    keys[0] = name; keys[1]= start; keys[2] = finish;
    keys[3] = type; keys[4] = till;
  }

  public String toString(){
    Formatter f = new Formatter();
    f.format("%-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s", name, start, finish, type, till, sBreakFast, sDinner, sAfternoon, sTea, sEvening);
    return f.toString();
  }

}

class RecordComparator implements Comparator<Record>{
  int sortKey;

  public RecordComparator(int sk){
    if (sk < 0 || sk > 4){
      sortKey = 0;
    }
    else{
      sortKey = sk;
    }
  }

  public RecordComparator(){
    this(0);
  }

  public int compare(Record r1, Record r2){
    String s1 = r1.keys[sortKey];
    String s2 = r2.keys[sortKey];
   
    return s1.compareTo(s2);
  }
}
 


The start variable is the one I would like to sort out as double..

Anyone with any idea’s?

Thanks
Coops
coops
 
Posts: 3
Joined: Sun Mar 11, 2007 9:37 am

Postby iron_alex on Tue Mar 13, 2007 10:11 pm

Could you be more specific? You mean you want to change the start variable from a string to a double and use comparisons based on its double value (to sort your records) ?
iron_alex
 
Posts: 2
Joined: Tue Mar 13, 2007 10:05 pm


Who is online

Users browsing this forum: No registered users and 0 guests