|
| 1 | +package org.launchcode.java.demos.lsn4school; |
| 2 | + |
| 3 | +public class Student { |
| 4 | + |
| 5 | + private static int nextStudentId = 1; |
| 6 | + private String name; |
| 7 | + private int studentId; |
| 8 | + private int numberOfCredits = 0; |
| 9 | + private double gpa = 0.0; |
| 10 | + |
| 11 | + public Student (String name, int studentId, int numberOfCredits, double gpa) { |
| 12 | + this.name = name; |
| 13 | + this.studentId = studentId; |
| 14 | + this.numberOfCredits = numberOfCredits; |
| 15 | + this.gpa = gpa; |
| 16 | + } |
| 17 | + |
| 18 | + public Student(String name, int studentId) { |
| 19 | + this(name, studentId, 0, 0); |
| 20 | + } |
| 21 | + |
| 22 | + public Student(String name) { |
| 23 | + this(name, nextStudentId); |
| 24 | + nextStudentId++; |
| 25 | + } |
| 26 | + |
| 27 | + public String studentInfo() { |
| 28 | + return (this.name + " has a GPA of: " + this.gpa); |
| 29 | + } |
| 30 | + |
| 31 | + // TODO: Complete the getGradeLevel method here: |
| 32 | + public String getGradeLevel() { |
| 33 | + // Determine the grade level of the student based on numberOfCredits |
| 34 | + } |
| 35 | + |
| 36 | + // TODO: Complete the addGrade method. |
| 37 | + public void addGrade(int courseCredits, double grade) { |
| 38 | + // Update the appropriate fields: numberOfCredits, gpa |
| 39 | + } |
| 40 | + |
| 41 | + // TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather |
| 42 | + // than just the class fields. |
| 43 | + |
| 44 | + // TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two |
| 45 | + // Student objects equal. |
| 46 | + |
| 47 | + public String getName() { |
| 48 | + return name; |
| 49 | + } |
| 50 | + |
| 51 | + public int getStudentId() { |
| 52 | + return studentId; |
| 53 | + } |
| 54 | + |
| 55 | + public int getNumberOfCredits() { |
| 56 | + return numberOfCredits; |
| 57 | + } |
| 58 | + |
| 59 | + public double getGpa() { |
| 60 | + return gpa; |
| 61 | + } |
| 62 | + |
| 63 | + public void setName(String name) { |
| 64 | + this.name = name; |
| 65 | + } |
| 66 | + |
| 67 | + public void setStudentId(int studentId) { |
| 68 | + this.studentId = studentId; |
| 69 | + } |
| 70 | + |
| 71 | + public void setGpa(double gpa) { |
| 72 | + this.gpa = gpa; |
| 73 | + } |
| 74 | + |
| 75 | + private void setNumberOfCredits(int numberOfCredits) { |
| 76 | + this.numberOfCredits = numberOfCredits; |
| 77 | + } |
| 78 | + |
| 79 | + public static void main(String[] args) { |
| 80 | + Student sally = new Student("Sally",1,1,4.0); |
| 81 | + System.out.println("The Student class works! " + sally.getName() + " is a student!"); |
| 82 | + System.out.println(sally); |
| 83 | + sally.addGrade(12, 3.5); |
| 84 | + System.out.println(sally); |
| 85 | + sally.addGrade(25, 3.8); |
| 86 | + System.out.println(sally); |
| 87 | + } |
| 88 | +} |
0 commit comments