-2

I need a little help with my application. I want to make a student tracker application in Java. The application should be able to add new students, years, courses, grades and average for grades. I'm using eclipse mars for it. Can you please tell me how to make the average for grades, and how to assign new year, courses, and grades for every student, please? Thank you.

enter code here public Student(String name, String year, String[] course, int [] grades) { super(); this.name = name; this.year = year; Course = course; Grades = grades; } private String name; private String year; private String[] Course; private int [] Grades;

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; public class 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 {

private String Courses; }

1 Answers1

0

Extend your Student class with the following method:

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

Afterwards you can print the average grade using:

System.out.println(a.getAverageGrade());
xry
  • 697
  • 1
  • 5
  • 21
  • Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method getAverageGrade() is undefined for the type Student at MainApplication.main(MainApplication.java:15) – Ene Cristian Jan 18 '16 at 01:06
  • The exception shouldn't be thrown when you get the getAverageGrade() method to your Student class. I hope everything will work fine right now! :-) – xry Jan 18 '16 at 15:43