Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-Task 2.8 Bring over your newly improved Student.java and Course.java code from 2.7. In this task, you will be making similar modifications to the Course

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
-Task 2.8 Bring over your newly improved Student.java and Course.java code from 2.7. In this task, you will be making similar modifications to the Course class. Instead of the numOfStudents field, we want an ArrayList that will store all of the Students enrolled in this course. Do the following: + 1. Replace the numofstudents field with a new field called enrolled students. It should be an ArrayList. 2. Modify the addNewStudent() method so that it now adds the input parameter (i.e. the Student object) to the enrolledStudents ArrayList. There should be no duplicates! Duplicate Students have the same id Similarly to Course, Student objects are distinctly identifiable by their id. Main.java Couro.java Student.java import java.util.ArrayList; public class Course private final String title Il title of the course private final String code; // course code private ArrayList ghrolledstudents - now ArrayList(); // the number of students enrolled private String instructor." // the name of the teacher of the course Creates a new course with the supplied attributes. The number of students 19 by default o. public Course(string title, String code) { this.title = title; this.code. code; } I Get this course's code. public String getCode() { return code;"> e * Get this course's title. public String getTitle() { return titlo;X Increments the number of enrolled students. public void addNewstudent() * Get the instructor of this course. public String getInstructor() { return instructor: In.java Course.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() { /** * Get the instructor of this course. 1 public String getInstructor() { return instructor ;) * Set the instructor of this course. */ public void setInstructor(String newInstructor) { instructor = newInstructor;) public boolean isSaneCourse(Course course) { (course.code this.code) { return true; } else { return false; } } ain.java Course.java Student.java import java.util.ArrayList; public class Student private String name; private String id; private ArrayList(); private boolean tuliload false; // the student's name // the student's id number Il courses the student is enrolled in 1/ does the student have a full course Load? Create a new student with the supplied attributes. Courses and guilload are defaulted to 6/false. public Student(String nome, String id) { this.name = name; this.id = id; } * Get the name of this student. public String getName() { return nano;) * * Set the name of this student. I P public void setName(String newNone) name = newlane; /** * Get the id of this student. */ public String getID) { return id; * Sot the id of this student. public void setId(String newID) (10 newID; * Add a course to this student's course Ust. A student can only be enrolled in 5 courses at a time. 2.8 src Main (2) Java X Student addCourse Course.java Student juva Add a course to this student's course lot. A student can only be enrolled in 5 courses at a time. public boolean alreadyCode (Course course) { boolean codi false; for(Course : coursos) { if(c. isSameCourse(course)) { code1 = true; break; } return code1; } public void addCourse(Course course) { 11 (ITULLLoad) { it (alreadyCode (course)) { courses.add(course); if (courses.size() -- 5) { fullLoad = true; } else { System.out.println("Course codo course.getCode(). "Already present"); I e Remove a course from this student's course list. public void removeCourse(Course course) { 1r (courses.remove(course)) FullLoad = false; #/ /** Print out the courses field. #/ public void printCourselist() { for (Course c : courses) { System.out.println(c.getTitle()+" c.getCode() + " Instructor: "..getInstructor())

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions