Below is the java code I have written to read the information and print the following information by creating various classes and methods.
Name:…… (name of student)
Current GPA:…..
Current grade average:…..
Can this be reduced to a single program/class by combining all the classes under a single program i.e without creating different classes?
Student class:
public class Student
{
   private String name;
   private double gpa;
   //methods
   public Student(){}
   public Student(String n,double g)
   {
   name=n;
   gpa=g;
   }
   //set the first name
   public void setName(String n)
   {
    name=n;
   }
    public void setGpa(double g)
   {
    gpa=g;
   }   
   //get methods
   public String getName(){return name;}
   public double getGpa(){return gpa;}
}
Marks class:
public class Marks extends Student
{
   //data
   private int grade[];
   //methods
   public Marks()
   {
   super();
   grade=new int[0];
   }
   public Marks(String n,double g, int k[])
   {
   super(n,g);
   grade=new int[k.length];
   for(int i=0;i<k.length;i++)
      grade[i]=k[i];
   }
   //average method
   public double  average()
   {
   double sum=0;
   for(int i=0;i<grade.length;i++)
   sum+=grade[i];
   return sum/grade.length;
   }  
}
Main class:
import java.io.*;
import java.util.Scanner;
public class Lab
{
   public static void main(String args[]) throws Exception
   {
   //data
   Student list[];  
   String name;
   double gpa;
   int k[], i,j;
   File toRead= new File("input.txt");
   Scanner get=new Scanner(toRead);
   //read input
   list=new Student[get.nextInt()];
   for(i=0;i<list.length;i++)
      {
          get.nextLine();
          name=get.nextLine();
          gpa=get.nextDouble();
          int gn=get.nextInt();
          k=new int[gn];
          for(j=0;j<k.length;j++)
          k[j]=get.nextInt();
          list[i]=new Marks(name,gpa,k); 
      }
   //print all the  name
   for(i=0;i<list.length;i++)
      System.out.printf("Name:%s\nGpa:%.2f\n",list[i].getName(),list[i].getGpa());
   //print average grades for student
   for(i=0;i<list.length;i++)
       {
       if(list[i] instanceof Marks)
         {
         Marks s=(Marks)list[i];
         System.out.printf("average: %s- %.2f\n", s.getName(),s.average());
         }
       }
   }
}
input.txt
3
Mark antony
3.4
10
100 100 90 80 34 56 78 90 89 80
Alex Smith Jr.
2.9
5
100 95 98 78 80
Mary J. John
3.4
12
35 56 100 100 90 98 87 89 88 77 67 95
