You are here: DEVPPL Forum Programming Java Forum
NOTIFICATIONS
54.329
MEMBERS
15.720
TOPICS
62.407
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Arrange Data by Lowest First

0

Loading

Arrange Data by Lowest First

Postby Coops » Sun Mar 11, 2007 10: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
 
Reputation: 0
Posts: 3
Joined: Sun Mar 11, 2007 10:37 am
Highscores: 0
Arcade winning challenges: 0

Arrange Data by Lowest First - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Postby Iron_alex » Tue Mar 13, 2007 11: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
 
Reputation: 0
Posts: 2
Joined: Tue Mar 13, 2007 11:05 pm
Highscores: 0
Arcade winning challenges: 0
cron
^ Back to Top