public class MarkScore{
private int[] arr;//the array to store the s
private int numItems;//number of items in the array
//String allItems;
//constructor,with a given length of the (empty) array
public MarkScore(int length){
int[] arr =new int[length];
}//end constructor
//constructor,with a given array to be wrapped
public MarkScore(int[] arr){
this.arr=arr;
}
// return the whole array
public int[] getMarkScore(){
return arr;
}
//return the current capacity of the array
public int capacity(){
return arr.length;
}
//return the number of items in the array
public int size(){
return numItems;
}
//return the item at the given position;
public int scoreAt(int index){
return arr[index];
}
//set the score at the given index pos
public void setScoreAt(int score,int index){
arr[index]=score;
}
-----------------------------------------------------------------------
//add the score at the end,and if needed let the array grow
//need to validate the score
public void addMarkScore(int score){
boolean vali;
if(0<=score && score<=100){
vali=true;
if(numItems<arr.length){
score=arr[arr.length-1];
}
else{ arr=new int[arr.length+1];//increase size? score=arr[arr.length-1];
}
}
vali=false;
}
----------------------------------------------------------------------
//return the items in a string ,separated by space
public String toString(){
String allItems="";
for (int i=0;i<=arr.length;i++){
allItems =arr[i]+"";
}//for loop
return allItems;
}
}//end class
addMarkScore(int score)这个方法我本身写的是不对的,可否帮我看看阿?
private int[] arr;//the array to store the s
private int numItems;//number of items in the array
//String allItems;
//constructor,with a given length of the (empty) array
public MarkScore(int length){
int[] arr =new int[length];
}//end constructor
//constructor,with a given array to be wrapped
public MarkScore(int[] arr){
this.arr=arr;
}
// return the whole array
public int[] getMarkScore(){
return arr;
}
//return the current capacity of the array
public int capacity(){
return arr.length;
}
//return the number of items in the array
public int size(){
return numItems;
}
//return the item at the given position;
public int scoreAt(int index){
return arr[index];
}
//set the score at the given index pos
public void setScoreAt(int score,int index){
arr[index]=score;
}
-----------------------------------------------------------------------
//add the score at the end,and if needed let the array grow
//need to validate the score
public void addMarkScore(int score){
boolean vali;
if(0<=score && score<=100){
vali=true;
if(numItems<arr.length){
score=arr[arr.length-1];
}
else{ arr=new int[arr.length+1];//increase size? score=arr[arr.length-1];
}
}
vali=false;
}
----------------------------------------------------------------------
//return the items in a string ,separated by space
public String toString(){
String allItems="";
for (int i=0;i<=arr.length;i++){
allItems =arr[i]+"";
}//for loop
return allItems;
}
}//end class
addMarkScore(int score)这个方法我本身写的是不对的,可否帮我看看阿?
private int numItems;//仅仅只定义了。
if(numItems<arr.length)//这里使用了。