Untitled
unknown
plain_text
2 years ago
1.2 kB
10
Indexable
import java.util.ArrayList;
public class Roster
{
// Implement the student ArrayList
// or copy from previous exercise
static ArrayList<Student> classList = new ArrayList<Student>();
public static void addStudent(String name, int grade)
{
// Create Student
Student NewStudent = new Student(name,grade);
// Add to classList
classList.add(NewStudent);
}
public static void addStudent(int index, String name, int grade)
{
Student NewStudent = new Student(name,grade);
classList.add(index, NewStudent);
}
public static String getLastStudent()
{
return classList.get(classList.size() - 1).getName();
}
public static int getClassSize()
{
return classList.size();
}
public static String getStudent(int index)
{
return classList.get(index).getName();
}
//Add the static methods here:
public static String printClassList()
{
String names = "";
for(Student name: classList)
{
names+= name.getName() + "\n";
}
return "Student Class List:\n" + names;
}
}Editor is loading...
Leave a Comment