下面的程序对着他们同在ScoresManager.java文件,但是当修改class Students为public class Students的时候就错,为什么?类缺省访问控制符:这个类只能被同一个包中的类访问或引用,我想问写在同一个文件下,是什么关系?同包?同文件?package Array;
import java.io.*;
class Students {
private double[] scores;
public Students(double[] s){
scores=new double[s.length];
for(int index=0;index <s.length;index++)scores[index]=s[index];
}
public double[] getScorceList(){
return scores;
}
public double getScore(int sno){
if(sno <1||sno> scores.length)return -1;
return scores[sno-1];
}
public boolean has(double score){
boolean found=false;
for(int index=0;index <scores.length;index++){
if(scores[index]==score) found=true;
}
return found;
}
public int count(double low,double high){
int result=0;
for(int index=0;index <scores.length;index++){
if(scores[index]> =low&&scores[index] <=high) result++;
}
return result;
}
public int countAll(){
return scores.length;
}
public void sort(){
for(int index=0;index <scores.length-1;index++){
for(int ptr=scores.length-1;ptr> index;ptr--){
if(scores[ptr]> scores[ptr-1]){
double temp=scores[ptr];
scores[ptr]=scores[ptr-1];
scores[ptr-1]=temp;
}
}
}
}
}
public class ScoresManager{
public static int inputNumer(){
int num;
try {
System.out.println( "请输入全班学生的人数,不合法的则返回 ");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
num=Integer.valueOf(inputLine).intValue();
} catch (IOException e) {
System.out.println( "学生人数输入错误! ");
return 0;
}
if(num <=0||num> 1000){
System.out.println( "输入的学生人数不合理 ");
return 0;
}
return num;
}
public static void input(double[] scoreList){
int index=0;
while(index <scoreList.length){
System.out.println( "第 "+(index+1)+ "为学生的成绩: ");
try {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String inputLine=in.readLine();
scoreList[index]=Integer.valueOf(inputLine).intValue();
} catch (IOException e) {
System.out.println( "输入成绩不合法 ");
continue;
}
if(scoreList[index] <0||scoreList[index]> 100){
System.out.println( "输入的成绩不在合理范围之内! ");
continue;
}
index=index+1;
}
}
public static void output(double[] scoreList){
for(int index=0;index <scoreList.length;index++){
System.out.println((index+1)+ ". "+scoreList[index]);
}
}
public static void main(String[] args){
int num=inputNumer();
if(num==0) return;
double[] scoreList=new double[num];
System.out.println( "请输入每一位学生的成绩 ");
input(scoreList);