Skip to content

Commit 7df53ac

Browse files
committed
Added starter code for the lesson 4 exercises.
1 parent 67ddaae commit 7df53ac

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.launchcode.java.demos.lsn4school;
2+
3+
import java.util.ArrayList;
4+
5+
public class Course {
6+
private String topic;
7+
private Teacher instructor;
8+
private ArrayList<Student> enrolledStudents;
9+
10+
// TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather than
11+
// just the class fields.
12+
13+
14+
// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
15+
// Course objects equal.
16+
17+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.launchcode.java.demos.lsn4school;
2+
3+
public class Teacher {
4+
private String firstName;
5+
private String lastName;
6+
private String subject;
7+
private int yearsTeaching;
8+
9+
public Teacher(String firstName, String lastName, String subject, int yearsTeaching) {
10+
this.firstName = firstName;
11+
this.lastName = lastName;
12+
this.subject = subject;
13+
this.yearsTeaching = yearsTeaching;
14+
}
15+
16+
public void setFirstName(String firstName) {
17+
this.firstName = firstName;
18+
}
19+
20+
public void setLastName(String lastName) {
21+
this.lastName = lastName;
22+
}
23+
24+
public void setSubject(String subject) {
25+
this.subject = subject;
26+
}
27+
28+
public void setYearsTeaching(int yearsTeaching) {
29+
this.yearsTeaching = yearsTeaching;
30+
}
31+
32+
public String getFirstName() {
33+
return firstName;
34+
}
35+
36+
public String getLastName() {
37+
return lastName;
38+
}
39+
40+
public String getSubject() {
41+
return subject;
42+
}
43+
44+
public int getYearsTeaching() {
45+
return yearsTeaching;
46+
}
47+
}

0 commit comments

Comments
 (0)