Student Tracker application

java

#1

Hey, 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.

Here is the student class

public class Student {

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;
}

public int medieNote (){
int medie = 0;

return medie;
}
}

Here is the Main application class

//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());
}

}

And here is the Course class
public class Course {
private String Courses;
}
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.


#2

Do you know how to create a method?

Do you know how to compute an average?

There's not much to explain here, go do it.


#3

that's the problem. I don't know how to make the average. And to create a method of what?


#4

You have lots of methods. Copy one and change the name.

An average is computed by summing the terms and dividing by the number of terms


#5

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


#6

I have used this method, but it doesn't work... :frowning:


#7

Looks about right to me. Perhaps you should look closer at in what way it doesn't work, that probably says a lot about what needs changing.


#8

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)

#9

This is the error that is displayed in console...


#10

Do you disagree with what that says? Maybe it needs moving.


#11

Moving where? In student class?


#12

Where is it supposed to be?
Where is it?


#13

Can you use teamviewer, please?


#14

I'm not pointing out what's wrong or saying what you should do anyhow. Smells far too much of homework.
I'll ask obvious questions for you to consider though, I'll go that far.

What does that error of yours say about the location of your method?
Where do you think it should be?
Where do you think it is?


#15

IT WORKED!! Now i have other problem... It does not displays the courses...


#16

in your code on this line

you are just returning the object(array) at its memory location(as raw data). To print out the array as a String you could use either of the static method java.util.Arrays.toString(array) or java.util.Arrays.asList(array) to achieve that
for example

String [] my_array = {"Mate","Fizica"};
System.out.(Arrays.toString(my_array));//[Mate, Fizica]

You would have to import the utility class java.util.Arrays to use it

NB: The method used above returns a String as specified by the doc in the link provided so you would have to reconsider your return type

There are many other ways to achieve this