Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now that the classList Array has been implemented, we need to create methods to access the list items. Create the following static methods for the

Now that the classList Array has been implemented, we need to create methods to access the list items.
Create the following static methods for the Student class:
getLastStudent() - returns the name of the last student in the classList array.
getClassSize() - returns the size of the classList
addStudent(int index, Student student) - adds a new student to the classList at index index. This method is a little tricky - when the new Student is added to the class, it will create a duplicate value at the end of the classList because of our Student constructor. This method should also include a command to remove the extra Student in the classList added to the end.
getStudent(int index) - returns the name of a student at the index specified.
Coding below was given to edit and use
public class ClassListTester
{
public static void main(String[] args)
{
//You don't need to change anything here, but feel free to add more Students!
Student alan = new Student("Alan", 11);
Student kevin = new Student("Kevin", 10);
Student annie = new Student("Annie", 12);
System.out.println(Student.printClassList());
System.out.println(Student.getLastStudent());
System.out.println(Student.getStudent(1));
Student.addStudent(2, new Student("Trevor", 12));
System.out.println(Student.printClassList());
System.out.println(Student.getClassSize());
}
}
import java.util.ArrayList;
public class Student
{
private String name;
private int grade;
//Implement classList here:
private static ArrayList classList = new ArrayList();
public Student(String name, int grade)
{
this.name = name;
this.grade = grade;
classList.add(this);
}
public String getName()
{
return this.name;
}
//Add the static methods here:
public static String printClassList()
{
String names = "";
for(Student name: classList)
{
names+= name.getName() + " ";
}
return "Student Class List: " + names;
}
}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Identify the primary emotion that is being interpreted as anger.

Answered: 1 week ago

Question

What is the preferred personality?

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago