public class Student {
String firstName;
String lastName;
Student(String fName, String lName)
{
firstName = fName;
lastName = lName;
}
void display()
{
System.out.println(firstName);
System.out.println(lastName);
}
}
import java.util.LinkedList;
public class ClassRoster {
static void orderPrint(LinkedList l)
{
int size = l.size();
for(int i=0; i < size; i++)
{
Student s =(Student) l.get(i);
s.display();
}
}
static void reverseOrderPrint(LinkedList l)
{
int size = l.size();
for(int i=size-1;i>=0;i--)
{
Student s =(Student) l.get(i);
s.display();
}
}
public static void main(String args[])
{
//Get 20 students information using loop
//I've used only two objects for the example
Student s1 = new Student("AA","BB");
Student s2 = new Student("CC","DD");
LinkedList l = new LinkedList();
l.add(s1);
l.add(s2);
// End of inputs
orderPrint(l);
reverseOrderPrint(l);
}
}
Let me know if u didnt understand any part