Example of Stack With Object Student
Example of Stack With Object Student
CLASS STUDENT
CLASS NODE
CLASS LINKEDLIST
CLASS STACK
CLASS APPLICATION
import javax.swing.JOptionPane;
public class StackApp2
{
public static void main(String [] args)
{
Stack theStack = new Stack(); // original stack
Stack tempStack = new Stack(); // temporary stack
for (int i=0; i<5; i++) // to input 5 students into the list
{ 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);
theStack.push(stud); } //insert data
// to display all the students in the stack
Object data;
Student S;
while (!theStack.isEmpty())
{
data = theStack.pop(); //delete first
S = (Student) data; //casting
System.out.println(S.toString()); //display
tempStack.push(S); // put into temporary stack
}
while (!theStack.isEmpty())
{
data = theStack.pop(); // pop from origional stack
S = (Student) data;
}
// display result
System.out.println("The highest cgpa = " + max);
System.out.println("The lowest cgpa = " + min);
System.out.println("The number of dean's list student = " + dList);
System.out.println("The number of part 4 student = " + part4);
System.out.println("The number of probation student = " + prob);
System.out.println("BEST STUDENT:");
System.out.println(bestStudent.toString());
} // main
} // StackApp