学生追踪应用程序

时间:2016-01-17 21:47:46

标签: java

我的申请需要一些帮助。我想用Java创建一个学生跟踪器应用程序。该应用程序应该能够添加新的学生,年,课程,成绩和平均成绩。我正在使用日食火星。 你能告诉我如何取得成绩的平均分,以及如何为每个学生分配新年,课程和成绩吗? 谢谢。

在这里输入代码     public Student(String name,String year,String [] course,int [] grade){         超();         this.name = name;         this.year =年;         课程=课程;         成绩=成绩;     }     私有字符串名称;     私人字符串年;     private String []课程;     private int []成绩;

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getYear() {
    return year;
}
public void setYear(String year) {
    this.year = year;
}
public String [] getCourse() {
    return Course;
}
public void setCourse(String[] course) {
    Course = course;
}
public int [] getGrades() {
    return Grades;
}
public void setGrades(int [] grades) {
    Grades = grades;
}
//import (default package).Student;

import java.util.Scanner; 公共类MainApplication {

public static void main(String[] args) {
    String [] w = {"Mate","Fizica"};
    int [] x = {8,9,10};
    Student a = new Student("Ene Cristian","Anul 2", w ,x);
    String [] y = {"Math", "Info"};
    int [] z = {7, 10 ,11};
    Student b = new Student("Popscu Ion","Anul 1", w, x);
    System.out.println(a.getName());
    System.out.println(a.getYear());
    System.out.println(b.getName());
    System.out.println(b.getYear());
}

}
public class Course {

私人弦乐课程;     }

1 个答案:

答案 0 :(得分:0)

使用以下方法扩展您的Student类:

public int getAverageGrade(){
    int averageGrade = 0;
    for(int grade : Grades){
        averageGrade = averageGrade + grade;
    }
    averageGrade = averageGrade/Grades.length;
    return averageGrade;
}

之后您可以使用以下方式打印平均成绩:

System.out.println(a.getAverageGrade());