Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java please Problem 3.1 Bring over your completed Course.java and Student.java Ples from 2.8. Noto that the versions Included here are not completo. Our

in java please image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Problem 3.1 Bring over your completed Course.java and Student.java Ples from 2.8. Noto that the versions Included here are not completo. Our completed Instructor.java file from Lab 1 is included here. We are going to be making some modifications. Make the following changes to Instructor.java: Create a new field called courses to store all of the Courses currently being taught by this instructor. You decide what type it should be (make a logical decision, there is a mark for this) We also want to transform the numStudents field into an ArrayList of students. This ArrayList will contain all of the Students that the Instructor is currently teaching This means you must update the assignNewCourse() method. The method should now take a Course object as a parameter. . The method should add the new Course to the courses field. Note that you cannot assign the Course to the instructor if the Instructor is already assigned to the Course (there is a course with the same code in courses ), . I the Course is added to courses, It should also take all the students enrolled in the Course and add them to the students ArrayList in Instructor (you will need an accessor method). You can assume that there are no duplicate students when writing your assignNewCourse() method. The previous functionally should remain the same, to the Instructor cannot be assigned a new Course if the new Course brings the total number of students to over 500. The method should still return a boolean based on whether or not the assigning was successful the assigning is successful, set the instructor field for the Course to that Instructor (Note: this is tricky). You will also need to modify the respective fields/methods in Course. Java so that an Instructor object is used instead of a String. The default value of instructor should be null . We still want a getNumStudents() method in Instructor.java. Make the required modifications so that the number of students the Instructor has is returned. De not re-add the old numStudents field, you do not need another field. Sblem 3.1 Sre Course 2.71 Mains 2.7/course.java 1 public class course Student.java 2.1../andre private final String title: private final String code; private int number of students = 0; private String Instructor . *"; 1/ 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 is by default . */ public Course(String title, String code) { 16 this.title = title: this.code = code: 1 10 11 12 13 14 15 14 17 18 19 22 23 34 25 26 29 30 31 Get this course's code. */ public String getCode(){return. code: e Get this course's titte. public String getTitle { return title; ./ CI / Increments the number of enrolled students. */ public void addNewstudent() { numberofstudents += 1; } S7 38 38 * Get the instructor of this course. */ public String getInstructor() { return instructor; . Set the instructor of this course. Terminal Build 231 m (35 minutes ago MacBook Pro Alain 3.1 are Course 2.71-/Main.java 2.71./Courseva Student.java 3.1-/Maine Course Creates a new course with the supplied attributes. The number of students is by default 8. public course(String title, String code) { this.title = title; this.code = code; } EL * Get this course's code. +/ public String getcode() { returni code: /* * Get this course's title. public String getTitle() { return title; / Increments the number of enrolled students. */ public void addrewstudent numberorstudents += 1; /** . Got the instructor of this course. A public String getInstructor() { return instructor: 7 0 66 Set the instructor of this course. */ public void set Instructor(String new instructor) ( Instructor newInstructor: 00 51 I Terminal Build 231 m (15 nutes ago MacBook Pro Kain. m 21 ore Student St. Import java.util.ArrayList public class Student private String nane private String id; private ArrayList01 // the student's none the student's id number // courses the student is enrolled in // does the student have a full course Lead? Create a new student with the supplied attribut attributes. Courses and sulllaed are defaulted to e/fatse. . public Student(String nano, String 1d) { this.name = name: this.id = id; } / Get the name of this student. */ public String getName() {return name: / / Set the name of this student. public void setName(String newtane) nane nenione; Je Get the id of this student. / public String getro { return id; Set the id of this student. .) public void setlo(string newid 10. newto: Add a course to this student's course Ust. A student can only be anrolled in courses at a time. Terminal (3 minutes ago MacBook Pro Problem 3.1 sre Student Main (0) Student java public String getID) { return 10; } 38 39 40 Set the ide of this student. public void setId(string newID) (id qwid; } 46 45 W/ 48 49 * 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; 50 51 52 ) 56 * Remove a course from this student's course list. public void renoveCourse Course course) { if (courses.removeCcourse)) FullLoad = false; / 55 56 57 61 62 63 64 65 06 67 68 69 70 71 G */ Print out the courses flold. public void printCourselist() { for Course c : courses) { System.out.println(c.getTitle()."". c.getCode()." Instructor:* c.getInstructor()); E Terminal Build Problem 3.1 src Instructor Student.java Instructor Java // STUDENT NAME // 2 e// STUDENT NUMBER // 3 public class Instructor { private String name; private String department; private boolean tenure; ; private int numStudents = 8; 10 11 12 13 14 15 16 public Instructor(String name, String department, boolean tenure) { this.name = name; this.department = department; this.tenure = tenure; } @ public String getName() { return name; } 19 20 public String getDepartment() { return department;) 23 24 public boolean getTenure() { return tenure; } public int getNumStudents() { return numStudents; } public void setTenure(boolean newValue) { tenure = newValue; } 27 28 31 32 35 36 37 38 39 40 public boolean assignNewCourse(int numNewStudents) { if (numStudents + numNew Students > 500) { return false; } numStudents += numNewStudents; return true; e 42

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

Students also viewed these Databases questions

Question

sharing of non-material benefits such as time and affection;

Answered: 1 week ago