I want to display the data of the arraylist student in tabular form. I have this code but it only displays the last set of data I input in the table. what is wrong with my code?
public class gradesummary extends student{
static ArrayList<student> studentList = new ArrayList<student>();
@SuppressWarnings("resource")
public static void main(String[] args){
student student = new student();
Scanner in = new Scanner(System.in);
for (int x=0; x<=10; x++){
System.out.print("Student Name: ");
try {
student.name = in.nextLine();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.print("Section: ");
try {
student.section = in.nextLine();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.print("Midterm Grade: ");
try {
student.mgrade = in.nextDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.print("Second Quarter Grade: ");
try {
student.sqgrade = in.nextDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.print("Final Exam Grade: ");
try {
student.fegrade = in.nextDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
student.fgrade = (student.mgrade*1/5)+(student.sqgrade*3/10)+(student.fegrade*9/20);
studentList.add(student);
in.nextLine();
}
Show(studentList);
}
private static void Show(ArrayList<student> studentList2) {
new student();
System.out.println(" Name Section Midterm Grade Second Quarter Grade Final Exam Grade Final Grade ");
for (int i=0;i<=10;i++)
{
student student1 = studentList.get(i);
System.out.println (" " +student1.name+ " "+student1.section+" "+student1.mgrade+" "+student1.sqgrade+" "+student1.fegrade+" "+student1.fgrade+" " );
}
}
}
this is the my class student
public class student {
String name;
String section;
Double mgrade;
Double sqgrade;
Double fegrade;
Double fgrade;
}

How can I make the table data straight? more organize? like this:
