
Java highscore
By: a guest on
May 27th, 2012 | syntax:
Java | size: 1.44 KB | hits: 28 | expires: Never
import java.util.*;
//class: highscore.java
public class highscore {
static List<Integer> scores = new ArrayList<Integer>();
static String sText;
static core c = new core();
public static void main(String[]args){
c.addScore();
c.setHighscore();
c.setText();
}
}
//class: core.java
public class core {
public void setHighscore() {
int counter = highscore.scores.size();
int mainCounter = 0;
int score1 = 0;
int score2 = 0;
int newscore1 = 0;
int newscore2 = 0;
while (mainCounter < highscore.scores.size()) {
while (0 <= counter && counter <= highscore.scores.size()) {
if (counter + 1 < highscore.scores.size()) {
score1 = counter;
score2 = counter + 1;
newscore1 = highscore.scores.get(score1);
newscore2 = highscore.scores.get(score2);
if (newscore1 < newscore2) {
highscore.scores.set(score1, newscore2);
highscore.scores.set(score2, newscore1);
}
}
counter--;
}
mainCounter++;
counter = highscore.scores.size();
}
}
public void addScore(){
highscore.scores.add(5);
highscore.scores.add(9);
highscore.scores.add(15);
}
public void setText() {
highscore.sText = "";
for (int i = 0; i < highscore.scores.size(); i++) {
highscore.sText = highscore.sText + "\n" + Integer.toString(i + 1) + ". "
+ highscore.scores.get(i);
}
System.out.println(highscore.sText);
}
}