Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java please. i have already added method 'isSameCourse' which i believe is correct. ~Task 2.7 We can store our own objects in collections. Take

in java please. i have already added method 'isSameCourse' which i believe is correct. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
~Task 2.7 We can store our own objects in collections. Take a look at Course.java and Student.java. They are mostly the same as Lab 1's Course and Student classes. Right now, our methods addCourse() and removeCourse() in Student.java do not work very well. There is no checking for duplicates in addCourse(), and removeCourse() only removes based on the object reference. We need courses to be uniquely identifiable based on their code . That requires that the addCourse() method check that there are no courses with identical codes already in the ArrayList before performing the addition. Likewise, removeCourse() should remove the course with the given course code if it exists in the ArrayList. Your task: 1. Define a new method in Course.java called isSameCourse(). This method should: . Take a Course object as the only parameter. Return a boolean true if the supplied Course object's code is equal to this' object's code. false otherwise. 2. Modify the addCourse() method in Student.java so that the addition is only performed if the Student's courses do not already contain a Course with the same code of the supplied Course. This check is in addition to the already implemented checks on fullLoad (1.e. a Student still cannot take more than 5 courses). 3. Modify the removeCourse() method in Student.java so that if a Course with the same code as the supplied Course exists in courses, it is removed. You can assume that all of the Student's Courses have different codes. This is a reasonable assumption if you implemented addCourse() correctly! fullLoad should still be modified accordingly: if a remove is performed the fullLoad field should be set to false. Course Java Student.java import java.util.ArrayList; public class Student private String name; private String id; private ArrayList(); private boolean fullLoad = false; // the student's name // the student's id number // courses the student is enrolled in Il does the student have a full course Load? Create a new student with the supplied attributes. Courses and fullLoad are defaulted to 6/false. public Student(String name, String 1d) { this.name = name; this.id = id; / * Get the name of this student. * public String getName() { return nomo;) * Set the name of this student. public void setName(String newone) name = newName; ) * Get the id of this student. */ public String getro() { return 0; } * Set the id of this student. */ public void setID(String newID) { 1d - newID;) * Add a course to this student's course list. A student can only be enrolled in 5 courses at a time. Course.java Studentava public String getID() { return id; Set the id of this student. public void setID(String newID) { 1d .newID;) B */ 3 Add a course to this student's course list. A student can only be enrolled in 5 courses at a time. public void addCourse(Course course) { if (ItullLoad) { courses.add(course); 11 (courses.size() == 5) fullload = true; *Remove a course from this student's course list. public void removeCourse(Course course) (at (courses.remove(course)) rullLoad = false; * Print out the courses field. public void printCourselist() { for (Course e : courses) { System.out.println(c.getTitle()"". c.getCode() + " Instructor:" + e.getInstructor()); in.java Student Java Course.java public class Course { private final String title; private final String code; private int number of students - @} private String Instructor = ""; Il title of the course // course code // the number of students enrolled // the name of the instructor of the course * Creates a new course with the supplied attributes. The number of students 1s by default 8. public Course(String title, String code) { this.title = title; this.code = code; } /** * Get this course's code. public String getCode() { return code;) I e * Get this course's title. */ public String getTitle() { return title;) * Increments the number of enrolled students. */ public void addNewStudent() { number of students += 1;3 e * Get the instructor of this course. */ public String getInstructor() { return instructor; * Set the instructor of this course. Java Courco.java Student Java public String getCode() { return code; } * Get this course's title. public String getTitle() { return title;) /** * Increments the number of enrolled students. */ public void addNewStudent() { numberOfStudents += 1;) * Get the instructor of this course. */ public String getInstructor() { return instructor;) * Set the instructor of this course, D public void setInstructor(String newInstructor) { instructor = newInstructor) public boolean issaneCourse(Course course) { (course.code this.code) { return true; } else { return false; e } e } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago