用java编写学生管理系统

2024-12-03 05:02:59
推荐回答(1个)
回答1:

我也是初学写的不好
public class Student {
static int[] gradesArray={87,68,94,100,83,78,85,91,76,87};
public Student(int[]gradesArray){

}
public void printAllGrade(){
for (int i = 0; i < gradesArray.length; i++) {
System.out.println("学号"+(i+1)+"成绩是"+gradesArray[i]);
}
}
public void printAvarage(){
double sum = 0;
for (int i = 0; i < gradesArray.length; i++) {
sum+=gradesArray[i];
}
System.out.println("\n平均成绩是"+sum/gradesArray.length);
}
public void printMax(){
int max=gradesArray[0];
for (int i = 0; i < gradesArray.length; i++) {
if(gradesArray[i]>max){
max=gradesArray[i];
}
}
System.out.println("\n最高分时"+max);
}
public void printMin(){
int min=gradesArray[0];
for (int i = 0; i < gradesArray.length; i++) {
if (gradesArray[i] min=gradesArray[i];
}
}
System.out.println("\n最低分时"+min);
}
public void printDistribution(){
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0;
for (int i = 0; i < gradesArray.length; i++) {
if(gradesArray[i]<10){
a++;
}else if (gradesArray[i]>=10&&gradesArray[i]<20) {
b++;
}
else if (gradesArray[i]>=20&&gradesArray[i]<30) {
c++;
}
else if (gradesArray[i]>=30&&gradesArray[i]<40) {
d++;
}
else if (gradesArray[i]>=40&&gradesArray[i]<50) {
e++;
}
else if (gradesArray[i]>=50&&gradesArray[i]<60) {
f++;
}
else if (gradesArray[i]>=60&&gradesArray[i]<70) {
g++;
}
else if (gradesArray[i]>=70&&gradesArray[i]<80) {
h++;
}
else if (gradesArray[i]>=80&&gradesArray[i]<90) {
j++;
}
else if (gradesArray[i]>=90&&gradesArray[i]<100) {
k++;
}
}
System.out.println("\n成绩分布是");
System.out.print("0-10:");
for (int i = 0; i <=a; i++) {
System.out.print("*");
}
System.out.print("10-20:");
for (int i = 0; i <=b; i++) {
System.out.print("*");
}
System.out.print("20-30:");
for (int i = 0; i <=c; i++) {
System.out.print("*");
}
System.out.print("30-40:");
for (int i = 0; i <=d; i++) {
System.out.print("*");
}
System.out.print("40-50:");
for (int i = 0; i <=e; i++) {
System.out.print("*");
}
System.out.print("50-60:");
for (int i = 0; i <=f; i++) {
System.out.print("*");
}
System.out.print("60-70:");
for (int i = 0; i <=g; i++) {
System.out.print("*");
}
System.out.print("70-80:");
for (int i = 0; i <=h; i++) {
System.out.print("*");
}
System.out.print("80-90:");
for (int i = 0; i <=j;i++) {
System.out.print("*");
}
System.out.print("90-100:");
for (int i = 0; i <=k; i++) {
System.out.print("*");
}
}
public static void main(String[] args) {
Student student=new Student(gradesArray);
student.printAllGrade();
student.printAvarage();
student.printMax();
student.printMin();
student.printDistribution();
}

}