Re: confused



Here is my code again:

import java.util.*;
public class ScoreSet
{
private ArrayList<Integer> scores;
private int average;
private int score;
private String toString;
public ScoreSet()
{
scores = new ArrayList<Integer>();
}
public void add(int score)
{
Integer wrapper = score;
scores.add(wrapper);
}
public double averageWithoutLowest2()
{
scores.add(95);
scores.add(90);
scores.add(90);
scores.add(68);
scores.add(78);
scores.add(68);
scores.add(68);
scores.add(80);
Collections.sort(scores);
average = (scores.get(2) + scores.get(3) + scores.get(4) +
scores.get(5) + scores.get(6) + scores.get(7)) / 6 ;
return average;
}
public String toString()
{
String _scores = " ";
for (int score : scores)
{
_scores += scores + " ";
}
return _scores;
}

public static void main(String[] args)
{
ScoreSet s = new ScoreSet();
//System.out.println("The average without the two lowest scores
is " + s.averageWithoutLowest2());
System.out.println(s.toString());
}
}

I still don't understand why it's displaying nothing. I added scores to
the score array in the averageWithoutLowest2 method, so I shouldn't
have to add them again should I? I am so confused.

.



Relevant Pages

  • Re: confused
    ... > public class ScoreSet ... > private int average; ... > private String toString; ... > the score array in the averageWithoutLowest2 method, ...
    (comp.lang.java.help)
  • Weird Problem in using MouseListener
    ... public class MouseInputTester extends java.applet.Applet { ... private int mouseX; ... public void mousePressed{ ... paint, ...
    (comp.lang.java)
  • Weird Problem in using MouseListener
    ... public class MouseInputTester extends java.applet.Applet { ... private int mouseX; ... public void mousePressed{ ... paint, ...
    (comp.lang.java.programmer)
  • Re: Multi-Threading problem
    ... private int seconds=0; ... private void secondsThread() { ... final MyClock myClock=new MyClock; ... public void run ...
    (comp.lang.java.programmer)
  • Cant compile (text to graphic window)
    ... I get the following error message when I try to compile the code below: ... {private int width; ... public void paintComponent ...
    (comp.lang.java.help)