Example Arraylist Adt
Example Arraylist Adt
1) CLASS DEFINITION
public Student()
{
id = -1;
name = "";
part = -1;
cgpa = -1.0;
2) CLASS APPLICATION
import javax.swing.JOptionPane;
import java.util.ArrayList;
// a) Get input 5 students details and insert into arraylist named theList
for (int i=0; i<5; i++)
{
String sIdStd = JOptionPane.showInputDialog("Enter student id");
String nameStd = JOptionPane.showInputDialog("Enter name");
String sPart = JOptionPane.showInputDialog("Enter part");
String sCgpa = JOptionPane.showInputDialog("Enter cgpa");
int iIdStd = Integer.parseInt(sIdStd);
int iPart = Integer.parseInt(sPart);
double dCgpa = Double.parseDouble(sCgpa);
Student stud = new Student(iIdStd, nameStd, iPart, dCgpa);
theList.add(stud);
}
// e) Count the number of students who score cgpa 3.00 and above
// in part4
if (S.getCgpa() > 3.00)
scorer++;
}
} // main
} // ArrayListApp