Hey guys, my Professor want us to come up with this code:

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 public methods:

A get method for each data element. For example:
public String getStudentName(); // note that the variable name 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 to get the actual final grade value!)

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 named gradeBookDriver.java. Do NOT modify gradeBookDriver; make your Student class meet the specified API so that the supplied gradeBookDriver works as-is.

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

Your output will look something like this:


------------------------------------------
Student: Andy
Location: UK
Contact information: andy@hotmail.com
Grade Report
------------------------------------------
Quiz 1 100
Quiz 2 80
Project 1 100
Project 2 90
Project 3 85
Project 4 95
Participation 0
Final Exam 80
-------
Final Grade: 66.0
------------------------------------------

------------------------------------------
Student: Heather
Location: Germany
Contact information: heather@hotmail.com
Grade Report
------------------------------------------
Quiz 1 80
Quiz 2 90
Project 1 100
Project 2 95
Project 3 95
Project 4 65
Participation 90
Final Exam 85
-------
Final Grade: 87.75

Im writing the code right now and will post what I have as I go. If anyone has a suggestion on the simplest way to do this please dont hestitate to share it with me.

Recommended Answers

All 12 Replies

Just get a text editor and start typing! But seriously, you have a detailed blow-by-blow description of what you have to do. It's detailed enough that you don't have any room for cleverness, so just do what it says.

Man I spent all night doing it and I just can figure out how to put it togheter.

OK, post what you've done so far (don't forget the code tags!) and someone here will have a look and give you some feedback and advice.

This is what I have so far, only the hierarchy. I am pretty confused as how to write the code inside the methods.

public 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 String getStudentName(); {}

public String getStudentEmail():{}

public String getStudentLocation();{}

public void setStudentName(int studentName); {}

public void setStudentEmail();{}

public void setStudentLocation();{}

public double finalGrade();

public void studentReport();

	
}

Here's some examples that are relevant, when you understand them you will be able to do yours:

public class Demo {
   int data;

   public void setData(int value) {
      data = value;
   }

   public int getData() {
      return data;
   }

   public int calculateDoubledData() {
      return data*2;
   }
}

Hey guys I managed to come up with this:

public class Student {

  private String studentName;
  private String studentEmail; 
  private String studentLocation;
  private int projectGrade1;
  private int projectGrade2;
  private int projectGrade3;
  private int projectGrade4;
  private int quizGrade1;
  private int quizGrade2;
  private int finalExam;
  private int participationGrades;


  public String getStudentName() {
	return studentName;	
	}

  public void setStudentName() {
	studentName = studentName;	
	}

  public String getStudentEmail(){
	return studentEmail;
	}

  public void setStudentEmail(){
	studentEmail = studentEmail;
	}

  public String getStudentLocation(){
	return studentLocation; 
	}

  public void setStudentLocation(){
	studentLocation = studentLocation;
	}	
  public double finalGrade(){
	
	double projectGrade = ((projectGrade1 * 0.1) + (projectGrade2 * 0.1) + (projectGrade3 * 0.1) + (projectGrade4 * 0.1));
	double quizGrade = ((quizGrade1 * 0.5) + (quizGrade2 * 0.5));
	double finalTest = (finalExam * 0.25);
	double participationGrade = (participationGrades * 0.25);
	double finalGpa = (projectGrade + quizGrade + finalTest + participationGrade);
	return finalGpa;
	}

  public void studentReport(){
  
	System.out.println("\t" + studentName + studentEmail + studentLocation + finalGrade());
	}
	
	
}

Its compiling but when I try to compile the driver given to us by the Professor I get this errors:

C:\JAVA>javac gradeBookDriver.java
gradeBookDriver.java:9: setStudentName() in Student cannot be applied to (java.l
ang.String)
cmis141Student1.setStudentName("Andy");
^
gradeBookDriver.java:10: setStudentEmail() in Student cannot be applied to (java
.lang.String)
cmis141Student1.setStudentEmail("andy@hotmail.com");
^
gradeBookDriver.java:11: setStudentLocation() in Student cannot be applied to (j
ava.lang.String)
cmis141Student1.setStudentLocation("UK");
^
gradeBookDriver.java:12: cannot find symbol
symbol : method setProjectGrade1(int)
location: class Student
cmis141Student1.setProjectGrade1(100);
^
gradeBookDriver.java:13: cannot find symbol
symbol : method setProjectGrade2(int)
location: class Student
cmis141Student1.setProjectGrade2(90);
^
gradeBookDriver.java:14: cannot find symbol
symbol : method setProjectGrade3(int)
location: class Student
cmis141Student1.setProjectGrade3(85);
^
gradeBookDriver.java:15: cannot find symbol
symbol : method setProjectGrade4(int)
location: class Student
cmis141Student1.setProjectGrade4(95);
^
gradeBookDriver.java:16: cannot find symbol
symbol : method setQuizGrade1(int)
location: class Student
cmis141Student1.setQuizGrade1(100);
^
gradeBookDriver.java:17: cannot find symbol
symbol : method setQuizGrade2(int)
location: class Student
cmis141Student1.setQuizGrade2(80);
^
gradeBookDriver.java:18: cannot find symbol
symbol : method setFinalExam(int)
location: class Student
cmis141Student1.setFinalExam(80);
^
gradeBookDriver.java:19: cannot find symbol
symbol : method setParticipationGrades(int)
location: class Student
cmis141Student1.setParticipationGrades(0);
^
gradeBookDriver.java:21: setStudentName() in Student cannot be applied to (java.
lang.String)
cmis141Student2.setStudentName("Heather");
^
gradeBookDriver.java:22: setStudentEmail() in Student cannot be applied to (java
.lang.String)
cmis141Student2.setStudentEmail("heather@hotmail.com");
^
gradeBookDriver.java:23: setStudentLocation() in Student cannot be applied to (j
ava.lang.String)
cmis141Student2.setStudentLocation("Germany");
^
gradeBookDriver.java:24: cannot find symbol
symbol : method setProjectGrade1(int)
location: class Student
cmis141Student2.setProjectGrade1(100);
^
gradeBookDriver.java:25: cannot find symbol
symbol : method setProjectGrade2(int)
location: class Student
cmis141Student2.setProjectGrade2(95);
^
gradeBookDriver.java:26: cannot find symbol
symbol : method setProjectGrade3(int)
location: class Student
cmis141Student2.setProjectGrade3(95);
^
gradeBookDriver.java:27: cannot find symbol
symbol : method setProjectGrade4(int)
location: class Student
cmis141Student2.setProjectGrade4(65);
^
gradeBookDriver.java:28: cannot find symbol
symbol : method setQuizGrade1(int)
location: class Student
cmis141Student2.setQuizGrade1(80);
^
gradeBookDriver.java:29: cannot find symbol
symbol : method setQuizGrade2(int)
location: class Student
cmis141Student2.setQuizGrade2(90);
^
gradeBookDriver.java:30: cannot find symbol
symbol : method setFinalExam(int)
location: class Student
cmis141Student2.setFinalExam(85);
^
gradeBookDriver.java:31: cannot find symbol
symbol : method setParticipationGrades(int)
location: class Student
cmis141Student2.setParticipationGrades(90);
^
22 errors

Please help me out, I got until 2400 EST today to turn this in.

thank you, good to know :-)

When you do a set method you must pass in the value that you want to set. So the test code says

cmis141Student1.setStudentName("Andy");

but you don't have a parameter corresponding to the new name "Andy"

public void setStudentName() { // no parameter
  studentName = studentName;  // this just sets studentName to whatever it was anyway (ie does nothing)
}

Have another look at the set method in example I gave you - it shows you how to use a parameter for the new value - you just have to adapt that idea to work with your code.

Hey James,

I modified to this, but its still giving me the same errors:

public String getStudentName() {
	return studentName;	
	}

  public void setStudentName(int stuName) {
	
	String studentName = "" + stuName;	
	}

  public String getStudentEmail(){
	return studentEmail;
	}

  public void setStudentEmail(int stuEmail){
	studentEmail = "" + stuEmail;
	}

  public String getStudentLocation(){
	return studentLocation; 
	}

  public void setStudentLocation(int stuLocation){
	studentLocation = "" + stuLocation;

Is that what you meant, if not, please explain it baby steps, I just started programming.

please, don't touch PC, hmmm anything pluged in electrocity, here is your Lab, note I ignored programing standards, just puts together yours ...

public delarations inside Strudent Class isn't jokes, but unused in this case

getter Methods inside Strudent Class isn't jokes, but unused in this case

public class GradeBookDriver {

    public static void main(String[] args) {
        Student cmis141Student1 = 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);
        cmis141Student1.studentReport();
        
        Student cmis141Student2 = new Student();
        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);
        cmis141Student2.studentReport();
    }

    private GradeBookDriver() {
    }
}

class Student {

    public String studentName;
    public String studentEmail;
    public String studentLocation;
    public int projectGrade1;
    public int projectGrade2;
    public int projectGrade3;
    public int projectGrade4;
    public int quizGrade1;
    public int quizGrade2;
    public int finalExam;
    public int participationGrades;

    public void setStudentName(String str) {
        this.studentName = str;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentEmail(String str) {
        this.studentEmail = str;
    }

    public String getStudentEmail() {
        return studentEmail;
    }

    public void setStudentLocation(String str) {
        this.studentLocation = str;
    }

    public String getStudentLocation() {
        return studentLocation;
    }

    public void setProjectGrade1(int num) {
        this.projectGrade1 = num;
    }

    public int getProjectGrade1() {
        return projectGrade1;
    }

    public void setProjectGrade2(int num) {
        this.projectGrade2 = num;
    }

    public int getProjectGrade2() {
        return projectGrade2;
    }

    public void setProjectGrade3(int num) {
        this.projectGrade3 = num;
    }

    public int getProjectGrade3() {
        return projectGrade3;
    }

    public void setProjectGrade4(int num) {
        this.projectGrade4 = num;
    }

    public int getProjectGrade4() {
        return projectGrade4;
    }

    public void setQuizGrade1(int num) {
        this.quizGrade1 = num;
    }

    public int getQuizGrade1() {
        return quizGrade1;
    }

    public void setQuizGrade2(int num) {
        this.quizGrade2 = num;
    }

    public int getQuizGrade2() {
        return quizGrade2;
    }

    public void setFinalExam(int num) {
        this.quizGrade1 = num;
    }

    public int getFinalExam() {
        return quizGrade1;
    }

    public void setParticipationGrades(int num) {
        this.quizGrade2 = num;
    }

    public int getParticipationGrades() {
        return quizGrade2;
    }

    public double finalGrade() {
        double projectGrade = ((projectGrade1 * 0.1) + (projectGrade2 * 0.1) + (projectGrade3 * 0.1) + (projectGrade4 * 0.1));
        double quizGrade = ((quizGrade1 * 0.5) + (quizGrade2 * 0.5));
        double finalTest = (finalExam * 0.25);
        double participationGrade = (participationGrades * 0.25);
        double finalGpa = (projectGrade + quizGrade + finalTest + participationGrade);
        return finalGpa;
    }

    public void studentReport() {
        System.out.println("\t" + studentName + " " + studentEmail + " " + studentLocation + " " + finalGrade());
    }
}

All right Thank You Mkorbel for that example, it opened my eyes and now I got everything to work except one thing. Im having trouble calculating the overall grade, Im pretty sure I did it wrong. Here is what I got so far:

public class Student {

    private String studentName;
    private String studentEmail;
    private String studentLocation;
    private int projectGrade1;
    private int projectGrade2;
    private int projectGrade3;
    private int projectGrade4;
    private int quizGrade1;
    private int quizGrade2;
    private int finalExam;
    private int participationGrades;

    public void setStudentName(String str) {
        this.studentName = str;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentEmail(String str) {
        this.studentEmail = str;
    }

    public String getStudentEmail() {
        return studentEmail;
    }

    public void setStudentLocation(String str) {
        this.studentLocation = str;
    }

    public String getStudentLocation() {
        return studentLocation;
    }

    public void setProjectGrade1(int proj1) {
        this.projectGrade1 = proj1;
    }

    public int getProjectGrade1() {
        return projectGrade1;
    }

    public void setProjectGrade2(int proj2) {
        this.projectGrade2 = proj2;
    }

    public int getProjectGrade2() {
        return projectGrade2;
    }

    public void setProjectGrade3(int proj3) {
        this.projectGrade3 = proj3;
    }

    public int getProjectGrade3() {
        return projectGrade3;
    }

    public void setProjectGrade4(int proj4) {
        this.projectGrade4 = proj4;
    }

    public int getProjectGrade4() {
        return projectGrade4;
    }

    public void setQuizGrade1(int qui1) {
        this.quizGrade1 = qui1;
    }

    public int getQuizGrade1() {
        return quizGrade1;
    }

    public void setQuizGrade2(int qui2) {
        this.quizGrade2 = qui2;
    }

    public int getQuizGrade2() {
        return quizGrade2;
    }

    public void setFinalExam(int finex) {
        this.finalExam = finex;
    }

    public int getFinalExam() {
        return finalExam;
    }

    public void setParticipationGrades(int num) {
        this.participationGrades = num;
    }

    public int getParticipationGrades() {
        return participationGrades;
    }

    public double finalGrade() {
        double projectGrade = ((projectGrade1 * 0.1) + (projectGrade2 * 0.1) + (projectGrade3 * 0.1) + (projectGrade4 * 0.1));
        double quizGrade = ((quizGrade1 * 0.5) + (quizGrade2 * 0.5));
        double finalTest = (finalExam * 0.25);
        double participationGrade = (participationGrades * 0.25);
        double finalGpa = (projectGrade + quizGrade + finalTest + participationGrade);
        return finalGpa;
    }

    public void studentReport() {
		System.out.println("--------------------");
		System.out.println("Student: " + studentName + "\n" + "Location: " + studentLocation + "\n" + "Contact information: " + studentEmail);
        System.out.println("Grade Report" + "\n" + "--------------------");
		System.out.println("Quiz1: " + quizGrade1 + "\n" + "Quiz2: " + quizGrade2);
		System.out.println("Project1: " + projectGrade1 + "\n" + "Project2: " + projectGrade2 + "\n" + "Project3: " + projectGrade3 + "\n" + "Project4: " + projectGrade4);
		System.out.println("Participation: " + participationGrades);
		System.out.println("Final Exam: " + finalExam);
    	System.out.println("------");
		System.out.println("Final Grade: " + finalGrade());
	}	
}

I am good to go now guys, Thank you very much!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.