| You are here: DEVPPL ‹ Forum ‹ Programming ‹ Java Forum |
NOTIFICATIONS
|
|
|||||||||||||||
Login |
Arrange Data by Lowest First
2 posts
• Page 1 of 1
0
Arrange Data by Lowest First
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:
The start variable is the one I would like to sort out as double..
Anyone with any idea’s?
Thanks
Coops
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
|
|