Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

CISS-110 Project 9

Posted on November 26, 2019April 28, 2025 By William Jojo
CISS-110-Project

Write a Java user-defined class called Student and a class tester program called Project9_lastname. These will be separate Java source files (Project9_lastname.java and Student.java).


Learning outcomes

  • Build a program using multiple source files.
  • Build a user-defined class.
  • Create overloaded mutators.
  • Create accessors and mutators.
  • Build code to test all code paths.

Important Note!
Be sure to review the Person class in Chapter 8. It will be your best guide for formatting and testing your code.

The Student class will consist of the following instance variables:

private String name;
private int test1, test2, finalExam;
private double average;

You will write the code for the following methods of the Student class:

public String toString()
public void setTest1(int t)
public void setTest2(int t)
public void setFinal(int finalExam)
public void setGrades(int t1, int t2, int f)
public void setName(String name)
public int getTest1()
public int getTest2()
public int getFinal()
public String getName()
public double getAverage()
[Note that setFinal() and setName() must use the this reference.]

In addition, you will write code for the following constructors of the Student class:

public Student()
public Student(String name)
public Student(String name, int test1, int test2, int finalExam)
[Note that the last two constructors must use the this reference.]

Whenever you call getAverage(), be sure to calculate the average at the time of the call.

The default values for grades should always be zero when not specified. The name should be the empty string (“”) when not provided.

The toString() method should return a String in the form:

“Name has test grades test1, test2 and finalExam and an average of average.”

The program Project9_lastname.java will exercise the Student class with reference variables student1, student2 and student3.

With the student1 reference variable, perform the following:

  • Use the Student() constructor.
  • Use the setName(), setTest1(), setTest2() and setFinal() mutator methods with the values “Bob Stevens”, 89, 92 and 93 respectively.
  • Use the getName(), getTest1(), getTest2(), getFinal() and getAverage() accessor methods to verify the content.
  • Test the toString() method.

With the student2 reference variable, perform the following:

  • Use the Student(String name) constructor with “James Kline”.
  • Use the setGrades() mutator method with values 75, 66, and 89, respectively.
  • Use the getName(), getTest1(), getTest2(), getFinal() and getAverage() accessor methods to verify the content.
  • Test the toString() method.

With the student3 reference variable, perform the following:

  • Use the Student(String name, int test1, int test2, int finalExam) constructor with the values “Nancy Keen”, 94, 97 and 100, respectively.
  • Use the setTest1() mutator method to correct the first test grade from 94 to 95.
  • Use the getName(), getTest1(), getTest2(), getFinal() and getAverage() accessor methods to verify the constructor and content.
  • Test the toString() method.

Your output should look something like this:

student1.getName() = Bob Stevens
student1.getTest1() = 89
student1.getTest2() = 92
student1.getFinal() = 93
student1.getAverage() = 91.333
Bob Stevens has test grades 89, 92 and 93 and an average of 91.333

student2.getName() = James Kline
student2.getTest1() = 75
student2.getTest2() = 66
student2.getFinal() = 89
student2.getAverage() = 76.667
James Kline has test grades 75, 66 and 89 and an average of 76.667

student3.getName() = Nancy Keen
student3.getTest1() = 95
student3.getTest2() = 97
student3.getFinal() = 100
student3.getAverage() = 97.333
Nancy Keen has test grades 95, 97 and 100 and an average of 97.333

Submit both Java files to the Learning Management System for grading.

Post navigation

❮ Previous Post: CISS-110 Project 8b – JavaFX
Next Post: Introduction ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.