- I want to create a student record using a method that is able to take input from user about student details . My class Student should consists of following fields : short semester, full name, registration number etc .registration number of a student = concatenation of year and student number. Eg year at which student joined = 2023, student no. = 80, So registration number = 2380
Plus I have been tasked to input date using class GregorianCalendar
INSIDE STUDENT CLASS:
import java.util.*;
class Student2{
    String fullname;
    GregorianCalendar date;
    short semester;
    Student2()
    {
    }
    Student2(String name,short sem, GregorianCalendar Date)
    {
        fullname = name;
        semester=sem;
        date = Date;
    }
    int years = date.get(Calendar.YEAR);
    String year = Integer.toString(years);
    String Studno = Integer.toString(80);
    String y1= year.substring(0,3);
    String Reg = y1.concat(Studno);
    int reg = Integer.parseInt(Reg);
    void Studarry()
    {
         int n=5,i;
         Student2[] stuarry = new Student2[10];
         for(i=0;i<n;i++)
         {
             System.out.println("Enter name sem year month day gpa cgpa\n");
             Scanner sc = new Scanner(System.in);
             String name = sc.nextLine();
             short sem2 = sc.nextShort();
             int year2 = sc.nextInt();
             int month2 = sc.nextInt();
             int day2=sc.nextInt()
             GregorianCalendar gc2 = new GregorianCalendar(year2,month2,day2);
             stuarry[i] = new Student2(name,sem2,gc2);
         }
    }
    void Display()
    {
    }
}
INSIDE DRIVER CLASS:
public class Greg2{
    public static void main(String[] args)
    { 
         Student2 starr = new Student2();
         starr.Studarry();
    }
}
ERRORS :
- Exception in thread "main" java.lang.NullPointerException - at oop2/lab5.Student2.<init>(Greg2.java:23) at oop2/lab5.Greg2.main(Greg2.java:68)
 
     
    