5.Assume that an examination authority conducts qualifying examination for candidates twice each year. First, in the month of June, second, in the month of December. Before the exam, it opens a registration process so that candidates register themselves. After the end of the registration dates, the authority consolidates the list of candidates and generates the unique register numbers. These numbers are assigned to each candidate. The format of the register numbers is as below. Each register number should contain exactly 10 characters
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class P5{
public static void main(String[] args) {
// creating objects st1 and st2 of class Student
int sizeN=5;
Student[] st = new Student[5];
int choice=0,i=0;
st[0]=new Student("Raj");
st[1]=new Student("RAVi");
st[2]=new Student("NAVEEN");
st[3]=new Student("RAMYA");
st[4]=new Student("AMRUTHA");
try{
System.out.println("Student Registration for Year :2021 ,cycle:2 ");
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
while(true){
System.out.println("Enter Choice 1: Register , 2:Display Register Numbers 3: EXIT");
choice = Integer.parseInt(reader.readLine());
boolean shouldBreak = false;
i=0;
switch(choice)
{
case 1:
st[i].addstudent();
st[i].generateRegisternumber();
break;
case 2:
System.out.println( " name : year : cycle : Registernumber");
for (i=0;i < sizeN;i++){
st[i].displayRegisterd();
}
break;
case 3:
shouldBreak=true;
break;
}
if (shouldBreak) break;
}
}catch(Exception e){}
}// end of main
}
class Student {
private String name;
private String Registernumber;
private int totalMarks;
public static String year="2021";
public static int cycle=2;
public static int count=0;
public Student(){}
public Student(String name){
this.name=name;
this.generateRegisternumber();
}
public void addstudent(){
try{
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Name : ");
this.name= reader.readLine();
System.out.println("student Succefully Registerd : ");
}catch(Exception e){
}
}
public void generateRegisternumber(){
StringBuilder sbStudent = new StringBuilder();
Student. count++;
sbStudent.append("BC");
sbStudent.append(Student.year);
sbStudent.append(Student.cycle);
sbStudent.append(String.format("%03d", Student.count));
this.Registernumber=sbStudent.toString();
}
public void displayRegisterd(){
System.out.println(this.name+" : " +Student.year+":"+Student.cycle+":"+this.Registernumber);
}
}