Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the course class that you have developed, change the array to arrayList and update the class so that it does all the tasks with

In the course class that you have developed, change the array to arrayList and update the class so that it does all the tasks with arrayList instead of array. (Update constructor, addStudent() and getStudent() methods) import java.util.ArrayList; public class Course { private int maximumEnrolment=50; private String courseName; private String courseNumber; //private Student[] students = new Student[maximumEnrolment]; private ArrayList students= new ArrayList<>(maximumEnrolment); private int numEnrolled=0; // default values in constructor public Course(){ this.courseName="Unknown"; this.courseNumber="Unknown"; this.maximumEnrolment=50; this.students=new ArrayList<>(maximumEnrolment); this.numEnrolled=0; } // parametrised constructor public Course(String name, String number,int maxEnrollment){ this.courseName=name; this.courseNumber=number; this.maximumEnrolment=maxEnrollment; this.students=new ArrayList<>(maximumEnrolment); this.numEnrolled=0; } //getters for coursename and coursenumber public String getCourseName(){ return this.courseName; } public String getCourseNumber(){ return this.courseNumber; } //setters for coursename and coursenumber public void setCourseName(String name){ this.courseName=name; } public void setCourseNumber(String number){ this.courseNumber=number; } // method to add the objects into the array of objects public void addStudent(Student aStudent){ students.add(numEnrolled, aStudent); numEnrolled++; } public Student getStudentAt(int anIndex){ return students.get(anIndex); } public int numberOfStudents(){ return numEnrolled; } //method to display all students public String toString(){ String output=""; for(int i=0;i

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

Optimizing Data Collection In Warzones

Authors: Aaget Aamber

1st Edition

B0CQRRFP5F, 979-8869065902

More Books

Students also viewed these Databases questions

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago