In: Computer Science
JAVA
StudentId: Consist of the first two characters of the student's first name, student's birth year, and the last two characters of the last name. For instance, if the student full name is John Doe and birthyear is 1995, then the id will be Jo1995oe. Birthday is using GregorianCalendar.
String firstname
String lastname
GregorianCalendar birthday
import java.util.Calendar;
import java.util.GregorianCalendar;
class Student {
private String ID;
private String fname;
private String lname;
private GregorianCalendar birthday;
public Student(String aFname, String aLname,
GregorianCalendar aBirthday) {
super();
fname = aFname;
lname = aLname;
birthday = aBirthday;
//generating ID with 2 chars from
first name and appending year and fetching last 2 chars from
lname
ID = fname.substring(0, 2) +
birthday.get(Calendar.YEAR) + lname.substring(lname.length() -
2);
}
public String getID() {
return ID;
}
public String getFname() {
return fname;
}
public String getLname() {
return lname;
}
public GregorianCalendar getBirthday() {
return birthday;
}
@Override
public String toString() {
return "ID : " + ID + ", fname : "
+ fname + ", lname : " + lname;
}
}
public class TestStudentID {
public static void main(String[] args) {
GregorianCalendar birth = new
GregorianCalendar(1995, 1, 1);
Student s = new Student("John",
"Doe", birth);
System.out.println(s);
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me