Don't like ads? PRO users don't see any ads ;-)
Guest

Java highscore

By: a guest on May 27th, 2012  |  syntax: Java  |  size: 1.44 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.*;
  2.  
  3. //class: highscore.java
  4. public class highscore {
  5.        
  6.         static List<Integer> scores = new ArrayList<Integer>();
  7.         static String sText;
  8.        
  9.         static core c = new core();
  10.         public static void main(String[]args){
  11.                
  12.                 c.addScore();
  13.                 c.setHighscore();
  14.                 c.setText();
  15.                
  16.         }
  17. }
  18.  
  19.  
  20. //class: core.java
  21. public class core {
  22.         public void setHighscore() {
  23.                 int counter = highscore.scores.size();
  24.                 int mainCounter = 0;
  25.  
  26.                 int score1 = 0;
  27.                 int score2 = 0;
  28.  
  29.                 int newscore1 = 0;
  30.                 int newscore2 = 0;
  31.                 while (mainCounter < highscore.scores.size()) {
  32.                         while (0 <= counter && counter <= highscore.scores.size()) {
  33.                                 if (counter + 1 < highscore.scores.size()) {
  34.                                         score1 = counter;
  35.                                         score2 = counter + 1;
  36.  
  37.                                         newscore1 = highscore.scores.get(score1);
  38.                                         newscore2 = highscore.scores.get(score2);
  39.  
  40.                                         if (newscore1 < newscore2) {
  41.  
  42.                                                 highscore.scores.set(score1, newscore2);
  43.                                                 highscore.scores.set(score2, newscore1);
  44.                                         }
  45.                                 }
  46.                                 counter--;
  47.                         }
  48.                         mainCounter++;
  49.                         counter = highscore.scores.size();
  50.                 }
  51.         }
  52.  
  53.         public void addScore(){
  54.                 highscore.scores.add(5);
  55.                 highscore.scores.add(9);
  56.                 highscore.scores.add(15);
  57.         }
  58.  
  59.         public void setText() {
  60.                 highscore.sText = "";
  61.                 for (int i = 0; i < highscore.scores.size(); i++) {
  62.                         highscore.sText = highscore.sText + "\n" + Integer.toString(i + 1) + ". "
  63.                                         + highscore.scores.get(i);
  64.                 }
  65.                 System.out.println(highscore.sText);
  66.         }
  67. }