Create a class called Student. This class should have the following twelve priva
ID: 3622795 • Letter: C
Question
Create a class called Student. This class should have the following twelve private data elements:
String studentName
String studentEmail
String studentLocation
int projectGrade1
int projectGrade2
int projectGrade3
int projectGrade4
int quizGrade1
int quizGrade2
int finalExam
int participationGrades
This class should have the following methods:
A get method for each data element. For example:
public String getStudentName(); // note that the variable starts with a lowercase, but in the method it’s uppercased.
A set method for each data element. For example:
public void setStudentName(String name);
public double finalGrade(); // computes final grade: project grades each * 0.1, plus quiz grades each * .05, plus final exam grade * .25, plus participation grade * .25.
public void studentReport(); // prints to the screen a reportcard that shows the student’s name, contact information, grade for each assignment, and final grade. (this method should call finalGrade() directly for this!)
Your project code will NOT have a main() method. You project must compile to create a file Student.class.
The below driver program will be used to test your class. Note that this should be compiled as a separate file.
public class gradeBookDriver {
public static void main (String[] args) {
Student cmis141Student1 = new Student();
Student cmis141Student2 = new Student();
cmis141Student1.setStudentName("Andy");
cmis141Student1.setStudentEmail("andy@hotmail.com");
cmis141Student1.setStudentLocation("UK");
cmis141Student1.setProjectGrade1(100);
cmis141Student1.setProjectGrade2(90);
cmis141Student1.setProjectGrade3(85);
cmis141Student1.setProjectGrade4(95);
cmis141Student1.setQuizGrade1(100);
cmis141Student1.setQuizGrade2(80);
cmis141Student1.setFinalExam(80);
cmis141Student1.setParticipationGrades(0);
cmis141Student2.setStudentName("Heather");
cmis141Student2.setStudentEmail("heather@hotmail.com");
cmis141Student2.setStudentLocation("Germany");
cmis141Student2.setProjectGrade1(100);
cmis141Student2.setProjectGrade2(95);
cmis141Student2.setProjectGrade3(95);
cmis141Student2.setProjectGrade4(65);
cmis141Student2.setQuizGrade1(80);
cmis141Student2.setQuizGrade2(90);
cmis141Student2.setFinalExam(85);
cmis141Student2.setParticipationGrades(90);
cmis141Student1.studentReport();
cmis141Student2.studentReport();
} // end of main() method
} // end of gradeBookDriver
This is what I have for the program but I cannot get it to work.
import java.util.*;
public class Student {
public static void main (String[] args) {
String studentName;
String studentEmail;
String studentLocation;
int[] projectGrades;
int[] quizGrades;
int finalExam;
int participationGrades;
public int getParticipationGrades() {
return participationGrades;
}
public void setParticipationGrades(int participationGrades) {
this.participationGrades = participationGrades;
}
public int getProjectGrades(int index) {
return projectGrades[index];
}
public void setProjectGrades(int index, int value) {
this.projectGrades[index] = value;
}
public int getQuizGrades(int index) {
return quizGrades[index];
}
public void setQuizGrades(int index, int value) {
this.quizGrades[index] = value;
}
public double finalGrade() {
double finalGrade = 0.0;
for (int val : projectGrades) {
finalGrade = finalGrade + (val * 0.1);
}
for (int val : quizGrades) {
finalGrade = finalGrade + (val * 0.05);
}
finalGrade = finalGrade + getFinalExam() * 0.25;
finalGrade = finalGrade + getParticipationGrades() * 0.25;
return finalGrade;
}
public Student() {
projectGrades = new int[4];
quizGrades = new int[2];
}
public void studentReport() {
System.out.println("------------------------------------------");
System.out.println("Student: " + getStudentName());
System.out.println("Location: " + getStudentLocation());
System.out.println("Contact information: " + getStudentEmail());
System.out.println("Grade Report");
System.out.println("------------------------------------------");
System.out.println("Quize 1 " + getQuizGrades(0));
System.out.println("Quize 2 " + getQuizGrades(1));
System.out.println("Project 1 " + getProjectGrades(0));
System.out.println("Project 2 " + getProjectGrades(1));
System.out.println("Project 3 " + getProjectGrades(2));
System.out.println("Project 4 " + getProjectGrades(3));
System.out.println("Participation " + getParticipationGrades());
System.out.println("Final Exam " + getFinalExam());
System.out.println("-------");
System.out.println("Final Grade "+finalGrade());
System.out.println("------------------------------------------");
}
public int getFinalExam() {
return finalExam;
}
public void setFinalExam(int finalExam) {
this.finalExam = finalExam;
}
public String getStudentEmail() {
return studentEmail;
}
public void setStudentEmail(String studentEmail) {
this.studentEmail = studentEmail;
}
public String getStudentLocation() {
return studentLocation;
}
public void setStudentLocation(String studentLocation) {
this.studentLocation = studentLocation;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
}
Explanation / Answer
please rate - thanks
I didn't check the math
class Student {
String studentName;
String studentEmail;
String studentLocation;
int projectGrade1;
int projectGrade2;
int projectGrade3;
int projectGrade4;
int quizGrade1;
int quizGrade2;
int finalExam;
int participationGrades;
public int getParticipationGrades() {
return participationGrades;
}
public void setParticipationGrades(int participationGrades) {
this.participationGrades = participationGrades;
}
public int getProjectGrade1() {
return projectGrade1;
}
public void setProjectGrade1( int value) {
this.projectGrade1= value;
}
public int getProjectGrade2() {
return projectGrade2;
}
public void setProjectGrade2( int value) {
this.projectGrade2= value;
}
public int getProjectGrade3() {
return projectGrade3;
}
public void setProjectGrade3( int value) {
this.projectGrade3= value;
}
public int getProjectGrade4() {
return projectGrade4;
}
public void setProjectGrade4( int value) {
this.projectGrade4= value;
}
public int getQuizGrade1() {
return quizGrade1;
}
public void setQuizGrade2(int value) {
this.quizGrade2= value;
}
public int getQuizGrade2() {
return quizGrade2;
}
public void setQuizGrade1(int value) {
this.quizGrade1= value;
}
public double finalGrade() {
double finalGrade = 0.0;
finalGrade = (projectGrade1+projectGrade2+projectGrade3+projectGrade4) * 0.1;
finalGrade = finalGrade + (quizGrade1+quizGrade2) * 0.0;
finalGrade = finalGrade + getFinalExam() * 0.25;
finalGrade = finalGrade + getParticipationGrades() * 0.25;
return finalGrade;
}
public void studentReport() {
System.out.println("------------------------------------------");
System.out.println("Student: " + getStudentName());
System.out.println("Location: " + getStudentLocation());
System.out.println("Contact information: " + getStudentEmail());
System.out.println("Grade Report");
System.out.println("------------------------------------------");
System.out.println("Quize 1 " + getQuizGrade1());
System.out.println("Quize 2 " + getQuizGrade2());
System.out.println("Project 1 " + getProjectGrade1());
System.out.println("Project 2 " + getProjectGrade2());
System.out.println("Project 3 " + getProjectGrade3());
System.out.println("Project 4 " + getProjectGrade4());
System.out.println("Participation " + getParticipationGrades());
System.out.println("Final Exam " + getFinalExam());
System.out.println("-------");
System.out.println("Final Grade "+finalGrade());
System.out.println("------------------------------------------");
}
public int getFinalExam() {
return finalExam;
}
public void setFinalExam(int finalExam) {
this.finalExam = finalExam;
}
public String getStudentEmail() {
return studentEmail;
}
public void setStudentEmail(String studentEmail) {
this.studentEmail = studentEmail;
}
public String getStudentLocation() {
return studentLocation;
}
public void setStudentLocation(String studentLocation) {
this.studentLocation = studentLocation;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.