This is from Y. Dianiel Liang\'s Introduction to Java Programming Exercise 11.5.
ID: 3654957 • Letter: T
Question
This is from Y. Dianiel Liang's Introduction to Java Programming Exercise 11.5. The Course class. Rewrite the Course class found in Listing 10.6. Use the ArrayList to replace and array to store students. Do not change the orginal contract of the Course class (i.e., the definition of the constructors and methods should not be changed. Use the following template: public class Exercise11_5 { public static void main(String[] args) { Course course1 = new Course("Data Structures"); Course course2 = new Course("Database Systems"); course1.addStudent("Peter Jones"); course1.addStudent("Brian Smith"); course1.addStudent("Anne Kennedy"); course2.addStudent("Peter Jones"); course2.addStudent("Steve Smith"); System.out.println("Number of students in course1: " + course1.getNumberOfStudents()); String[] students = course1.getStudents(); for (int i = 0; i < course1.getNumberOfStudents(); i++) System.out.print(students[i] + ", "); System.out.println(); System.out.print("Number of students in course2: " + course2.getNumberOfStudents()); } } class Course { // Implement it }Explanation / Answer
import java.util.*; public class Exercise11_05 { public static void main(String[] args) { Course course1 = new Course("Data Structures"); Course course2 = new Course("Database Systems"); course1.addStudent("Peter Jones"); course1.addStudent("Brian Smith"); course1.addStudent("Anne Kennedy"); course1.addStudent("Susan Kennedy"); course1.addStudent("John Kennedy"); course1.addStudent("Kim Johnson"); course1.addStudent("S1"); course1.addStudent("S2"); course1.addStudent("S3"); course1.addStudent("S4"); course1.addStudent("S5"); course1.addStudent("S6"); course1.addStudent("S7"); course2.addStudent("Peter Jones"); course2.addStudent("Steve Smith"); System.out.println("Number of students in course1: " + course1.getNumberOfStudents()); String[] students = course1.getStudents(); for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.