I made a very simple program where you input a students grades (edit the code with the set method?) and the program will output the average. Each test has a different weight associated with it.
The problems I think I have right now are:
I am not properly utilizing my methods. The getters and setters are probably done wrong.
Should I make
testScore1
its own class since a test can have a test score, test worth % (weight)?Is it good coding practice to use code separators to separate code for easier viewing?
Main question
- Should the declaring of a students name and grades be inside the student class or was I correct in setting them in the main method? (I think that a student's info (name and grades) should be kept inside the Student class and that the main method should be using get methods to access them rather than setting them. Is my thinking correct?)
The basis of what I am trying to achieve is the first comment in my code.
- Pastebin link for
application
class - Pastebin link for
Student
class
application
class
/*
* --- Student Grade Book Application ---
* Keep track of students (with a student class that has their name, average, and scores) in a class and their grades.
* Assign their scores on tests and assignments to the students and figure out their average and grade for the class.
* For added complexity put the students on a bell curve.
*/
// I think this will require multidimensional arrays
public class application {
public static void main(String[] args) {
Student student1 = new Student();
student1.setName("Bob"); // Should the name of the student be declared here with a setName?
student1.setTestScore1(80);
student1.setTestScore2(60);
student1.setFinalExamScore(90);
student1.calculateEntireAverage();
System.out.println(student1.calculateEntireAverage() + "%");
}
}
Student
class
public class Student{
private String name;
private double average;
private double testScore1; // worth 25% (should I make testScore1 it's own class since a test can have a test score, test worth %)
private double testScore2; // worth 25%
private double finalExamScore; // worth 50%
// Getter for name
public String getName() {
return name;
}
// Setter for name
public void setName(String name) {
this.name = name;
}
// ----------------------------------------------------
// Getter for testScore1
public double getTestScore1() {
return testScore1;
}
// Setter for testScore1
public void setTestScore1(double testScore1) {
this.testScore1 = testScore1;
}
// Getter for testScore2
public double getTestScore2() {
return testScore2;
}
// Setter for testScore2
public void setTestScore2(double testScore2) {
this.testScore2 = testScore2;
}
// ----------------------------------------------------
// Getter for finalExamScore
public double getFinalExamScore() {
return finalExamScore;
}
// Setter for finalExamScore
public void setFinalExamScore(double finalExamScore) {
this.finalExamScore = finalExamScore;
}
// ----------------------------------------------------
// Getter for average
public double getAverage() {
return average;
}
// I think this is essentially a setter for average
public double calculateEntireAverage() {
average = (testScore1*0.25 + testScore2*0.25 + finalExamScore*0.5);
// am I just supposed to use a getter / setter for the average instead of making a method like this?
return average;
}
}