Date: November 12
This document shows the spec sheet, pseudocode, and Java source code for the
Student class and the StudentDriver class. The driver class creates
(instantiates) a Student object and calls its methods. All methods in the
Student class have a void return type.
Student ClassFile Name: Student.java
Class Name: Student
Type: Blueprint class (will be used to create Student objects)
The Student class models a high school student with a name, grade level, and GPA.
It provides methods to change the student’s data and display it. All methods have a
void return type.
| Name | Type | Description |
|---|---|---|
name |
String |
Student’s name |
gradeLevel |
int |
Student’s current grade level (9–12) |
gpa |
double |
Student’s GPA (0.0–4.0) |
void)setName(String n)n – the new name.voidsetGradeLevel(int grade)grade – the new grade level.voidsetGpa(double g)g – the new GPA.voidprintStudentInfo()voidpromote()voidresetStudent()voidStudent Class
CLASS Student
// Fields
DECLARE name AS String
DECLARE gradeLevel AS int
DECLARE gpa AS double
METHOD setName(n AS String)
SET name TO n
END METHOD
METHOD setGradeLevel(grade AS int)
SET gradeLevel TO grade
END METHOD
METHOD setGpa(g AS double)
SET gpa TO g
END METHOD
METHOD printStudentInfo()
DISPLAY "Student Name: " + name
DISPLAY "Grade Level: " + gradeLevel
DISPLAY "GPA: " + gpa
END METHOD
METHOD promote()
INCREASE gradeLevel BY 1
DISPLAY name + " has been promoted to grade " + gradeLevel
END METHOD
METHOD resetStudent()
SET name TO empty string
SET gradeLevel TO 0
SET gpa TO 0.0
DISPLAY "Student record reset."
END METHOD
END CLASS
StudentDriver ClassFile Name: StudentDriver.java
Class Name: StudentDriver
Type: Driver / test class (has main method)
The StudentDriver class tests the Student class. It creates
(instantiates) one Student object and calls the methods to demonstrate
instantiation and method calls.
public static void main(String[] args)Student object.StudentDriver Class
CLASS StudentDriver
METHOD main(args)
// 1. Create (instantiate) a Student object
DECLARE s1 AS Student
SET s1 TO NEW Student object
// 2. Set the student's data
CALL s1.setName("Aiden")
CALL s1.setGradeLevel(11)
CALL s1.setGpa(3.75)
// 3. Print student information
CALL s1.printStudentInfo()
// 4. Promote the student
CALL s1.promote()
// 5. Reset the student record
CALL s1.resetStudent()
END METHOD
END CLASS
Submit the following to you google drive under your class name and Google Classroom: