62,568
社区成员




class Student {
private String studentName;
private String[] courseName;
private int[] courseScore;
public Student(String studentName, String[] courseName,int[] courseScore;) {
this.studentName = studentName;
this.courseName = courseName;
this.courseScore = courseScore;
}
private int sum() {
int sum = 0;
for(int i=0; i<courseScore.length; i++) {
sum += courses[i];
}
return sum;
}
private double avg() {
return this.sum() / courses.length;
}
public void printStudentInfo() {
System.out.println("StudentName:\t\t" + studentName);
for(int i=0; i<courseScore.length; i++) {
System.out.println(courseName[i] + ":\t\t" + courseScore[i]);
}
System.out.println("TotalScore:\t\t" + this.sum());
System.out.println("Average:\t\t" + this.avg());
}
}
public class MainClass {
public static void main(String[] args) {
String studentName = "James.King";
Course courseA = new Course("courseA", 60);
Course courseB = new Course("courseB", 70);
Course courseC = new Course("courseC", 80);
Course courseD = new Course("courseD", 90);
Course courseE = new Course("courseE", 100);
String[] course = new String{"courseA","courseB","courseC","courseD","courseE"};
int[] score = new int{60,70,80,85,90};
Student student = new Student(studentName, course[5],score[5]);
student.printStudentInfo();
}
}
public class Student {
private String studentName;
private String[] courseName;
private int[] courseScore;
public Student(String studentName, String[] courseName,int[] courseScore) {
this.studentName = studentName;
this.courseName = courseName;
this.courseScore = courseScore;
}
private int sum() {
int sum = 0;
for(int i=0; i<courseScore.length; i++) {
sum += courseScore[i];
}
return sum;
}
private double avg() {
return this.sum() / courseScore.length;
}
public void printStudentInfo() {
System.out.println("StudentName:\t\t" + studentName);
for(int i=0; i<courseScore.length; i++) {
System.out.println(courseName[i] + ":\t\t" + courseScore[i]);
}
System.out.println("TotalScore:\t\t" + this.sum());
System.out.println("Average:\t\t" + this.avg());
}
}
public class MainClass {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String studentName = "James.King";
String[] course = new String[]{"courseA","courseB","courseC","courseD","courseE"};
int[] score = new int[]{60,70,80,85,90};
Student student = new Student(studentName, course[5],score[5]);
student.printStudentInfo();
}
}