Re: confused
- From: "andreas kinell" <news@xxxxxxxxx>
- Date: Sun, 30 Oct 2005 01:47:40 +0200
"CPSCmajor" <bmerritt1987@xxxxxxxxx> schrieb im Newsbeitrag
news:1130615360.592335.207380@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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.
>
You don't actually invoke the averageWithoutLowest2() method, because you
invoke it as part of the arguments of your System.out.println() and that
line is commented out.
andreas
.
- Follow-Ups:
- Re: confused
- From: CPSCmajor
- Re: confused
- References:
- Re: confused
- From: CPSCmajor
- Re: confused
- From: CPSCmajor
- Re: confused
- Prev by Date: Re: network is hindering my applet
- Next by Date: Re: Desing Question re Multiple Constructors
- Previous by thread: Re: confused
- Next by thread: Re: confused
- Index(es):
Relevant Pages
|
|