I Would like to create a High Score For a Game in jave Called Jetman. i have created a class in java called Score and Score list to display the score but i do not know how to create a highscore using an Array List
the Score Class is
package jetman;
import java.io.Serializable;
public class Score implements Comparable<Score>,
Serializable {
private String name;//int should have more than enough space - if score overflows
private int score; //the user's cheated so they can accept the concequences!!
/** Creates a new instance of Score */
public Score(String name, int score) {
this.name = name;
this.score = score;
}
public Score(){
this.name = "";
this.score = -1;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int compareTo(Score o) {
return score - o.score;
}
int getNumRecords() {
return 0;
}
}
and the Score List is
package jetman;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
public class scoreList {
String filePath = "./score.txt";
private ArrayList<Score> scoreArrayList = new ArrayList<Score>();
/** Creates a new instance of scoreList */
public scoreList() {
FileWriter writer = null;
try {
writer = new FileWriter("output.txt");
} catch (IOException ex) {
ex.printStackTrace();
}
PrintWriter out = new PrintWriter(writer);
out.println(this);
out.println(10.55);
//this.add(scoreArrayList);
}
public ArrayList<Score> getScoreArrayList() {
return scoreArrayList;
}
public void setScoreArrayList(ArrayList<Score> scoreArrayList) {
this.scoreArrayList = scoreArrayList;
}
public void removeScoreArrayList (Score s) {
scoreArrayList.remove(s);
this.scoreArrayList = scoreArrayList;
}
private Score add(Score s) {
scoreArrayList.add(s);
return s;
}
}
Thank You