Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how do use the method record(int score) in this code?

807591May 1 2008 — edited May 4 2008
how do i use record(int score) from the class Stats to record a new score?
public class ScoreInfo {
 private int score;
 private int numStudents;
 
 public ScoreInfo(int aScore){
	 score = aScore;
	 numStudents=1;
 }
 public void increment(){numStudents++;}
 public int getScore(){return score;}
 public int getFrequency(){return numStudents;}
}
import java.util.ArrayList;
import java.*; 
 
public class Stats
{
 
private ArrayList<ScoreInfo> scoreList;
 
public boolean record(int score)
{
	int k=0;
	while(k<scoreList.size() && score > scoreList.get(k).getScore()){
		k++;
	}
	
	boolean found = k<scoreList.size() && score == scoreList.get(k).getScore();
	
	 if(found){scoreList.get(k).increment();}
	 else{scoreList.add(k,new ScoreInfo(score));}
	 
	 return found;
}
 
public void recordScores(int[] stuScores)
{
	
}
static int score = 50;
public static void main(String[] args) throws Exception
{
 Stats stats = new Stats();
 ScoreInfo thestat = new ScoreInfo(score);
 stats.scoreList.add(thestat);
}
 
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2008
Added on May 1 2008
7 comments
1,084 views