Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/org/launchcode/java/demos/lsn4school/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.launchcode.java.demos.lsn4school;

import java.util.ArrayList;

public class Course {
private String topic;
private Teacher instructor;
private ArrayList<Student> enrolledStudents;

// TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather than
// just the class fields.


// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
// Course objects equal.

}
88 changes: 88 additions & 0 deletions src/org/launchcode/java/demos/lsn4school/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.launchcode.java.demos.lsn4school;

public class Student {

private static int nextStudentId = 1;
private String name;
private int studentId;
private int numberOfCredits = 0;
private double gpa = 0.0;

public Student (String name, int studentId, int numberOfCredits, double gpa) {
this.name = name;
this.studentId = studentId;
this.numberOfCredits = numberOfCredits;
this.gpa = gpa;
}

public Student(String name, int studentId) {
this(name, studentId, 0, 0);
}

public Student(String name) {
this(name, nextStudentId);
nextStudentId++;
}

public String studentInfo() {
return (this.name + " has a GPA of: " + this.gpa);
}

// TODO: Complete the getGradeLevel method here:
public String getGradeLevel() {
// Determine the grade level of the student based on numberOfCredits
}

// TODO: Complete the addGrade method.
public void addGrade(int courseCredits, double grade) {
// Update the appropriate fields: numberOfCredits, gpa
}

// TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather
// than just the class fields.

// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
// Student objects equal.

public String getName() {
return name;
}

public int getStudentId() {
return studentId;
}

public int getNumberOfCredits() {
return numberOfCredits;
}

public double getGpa() {
return gpa;
}

public void setName(String name) {
this.name = name;
}

public void setStudentId(int studentId) {
this.studentId = studentId;
}

public void setGpa(double gpa) {
this.gpa = gpa;
}

private void setNumberOfCredits(int numberOfCredits) {
this.numberOfCredits = numberOfCredits;
}

public static void main(String[] args) {
Student sally = new Student("Sally",1,1,4.0);
System.out.println("The Student class works! " + sally.getName() + " is a student!");
System.out.println(sally);
sally.addGrade(12, 3.5);
System.out.println(sally);
sally.addGrade(25, 3.8);
System.out.println(sally);
}
}
47 changes: 47 additions & 0 deletions src/org/launchcode/java/demos/lsn4school/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.launchcode.java.demos.lsn4school;

public class Teacher {
private String firstName;
private String lastName;
private String subject;
private int yearsTeaching;

public Teacher(String firstName, String lastName, String subject, int yearsTeaching) {
this.firstName = firstName;
this.lastName = lastName;
this.subject = subject;
this.yearsTeaching = yearsTeaching;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void setYearsTeaching(int yearsTeaching) {
this.yearsTeaching = yearsTeaching;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getSubject() {
return subject;
}

public int getYearsTeaching() {
return yearsTeaching;
}
}