Question: 10.13 zyLab: Drop Student Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent()
10.13 zyLab: Drop Student
Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent() as described below. Refer to Student.java below to learn what methods are available.
Code:
import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{
/** collection of Students */ private ArrayList
/***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList
/***************************************************** Remove student with the provided last name. Do nothing if last name not found. *****************************************************/ public void dropStudent(String last){ /** Your code goes here */ } /***************************************************** Add a student to the course *****************************************************/ public void addStudent(Student s){ roster.add(s); } public int countStudents(){ return roster.size(); } /***************************************************** Main method for testing *****************************************************/ public static void main(String args[]){ Course cis162 = new Course(); cis162.addStudent(new Student("Henry", "Cabot", 3.5)); cis162.addStudent(new Student("Brenda", "Stern", 2.0)); cis162.addStudent(new Student("Lynda", "Robison", 3.2)); cis162.addStudent(new Student("Jane", "Flynn", 3.9)); cis162.dropStudent("Stern"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
