In: Computer Science
Create a class called Student.
Create another class called CourseSection
Create a client that tests the CourseSection class. Test the accessors, mutators, equals, to toString method. Ultimately, this will also be testing the Student class because instances of Student are in the Course Section class.
SOURCE CODE: *Please follow the comments to better understand the code. **Please look at the Screenshot below and use this code to copy-paste. ***The code in the below screenshot is neatly indented for better understanding. This is a very big question. I have solved all of them. Please give me an upvote dear, Much Appreciated.!! ====== Stduent.java ====== package demo; import java.util.Objects; public class Student { private String name; private String address; private String Phone; private double GPA; // Constructor public Student() { } public Student(String name, String address, String phone, double GPA) { this.name = name; this.address = address; Phone = phone; this.GPA = GPA; } // accessor and mutator public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPhone() { return Phone; } public void setPhone(String phone) { Phone = phone; } public double getGPA() { return GPA; } public void setGPA(double GPA) { this.GPA = GPA; } // toString @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", address='" + address + '\'' + ", Phone='" + Phone + '\'' + ", GPA=" + GPA + '}'; } // equals() @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Student)) return false; Student student = (Student) o; return Double.compare(student.getGPA(), getGPA()) == 0 && Objects.equals(getName(), student.getName()) && Objects.equals(getAddress(), student.getAddress()) && Objects.equals(getPhone(), student.getPhone()); } }
=======
CourseSection.java
=======
package demo; import java.util.Objects; public class CourseSection { private String courseName; private int days; private String timesCourseMeets; private String description; private Student a; private Student b; private Student c; // Constructor public CourseSection() { } public CourseSection(String courseName, int days, String timesCourseMeets, String description, Student a, Student b, Student c) { this.courseName = courseName; this.days = days; this.timesCourseMeets = timesCourseMeets; this.description = description; this.a = a; this.b = b; this.c = c; } // Accessor and mutator public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public int getDays() { return days; } public void setDays(int days) { this.days = days; } public String getTimesCourseMeets() { return timesCourseMeets; } public void setTimesCourseMeets(String timesCourseMeets) { this.timesCourseMeets = timesCourseMeets; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Student getA() { return a; } public void setA(Student a) { this.a = a; } public Student getB() { return b; } public void setB(Student b) { this.b = b; } public Student getC() { return c; } public void setC(Student c) { this.c = c; } // toString() @Override public String toString() { return "CourseSection{" + "courseName='" + courseName + '\'' + ", days=" + days + ", timesCourseMeets='" + timesCourseMeets + '\'' + ", description='" + description + '\'' + ", a=" + a + ", b=" + b + ", c=" + c + '}'; } // equals() @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CourseSection)) return false; CourseSection that = (CourseSection) o; return getDays() == that.getDays() && Objects.equals(getCourseName(), that.getCourseName()) && Objects.equals(getTimesCourseMeets(), that.getTimesCourseMeets()) && Objects.equals(getDescription(), that.getDescription()) && Objects.equals(getA(), that.getA()) && Objects.equals(getB(), that.getB()) && Objects.equals(getC(), that.getC()); } }
=======