Create a Student class with the following: A private String variable named “fNam
ID: 3634453 • Letter: C
Question
Create a Student class with the following:A private String variable named “fName” to store the student’s first name
A private String variable named “mName” to store the student’s middle name
A private String variable named “lName” to store the student’s last name
A private String variable named “UFID” that contains the unique ID number for this student
A private String variable named “DOB” to store the student’s date of birth
A public constructor Student() which will set default names, IDs and DOB:
Several public set methods:
SetNames(String name) will store the first word in name to fName, last word to lName, and if the name contains a middle name, store in mName. (Note: it is possible that the input String has just two words, but never 4 or more words.)
SetUFID(String id) will check whether id is a valid UFID in the format of xxxx-xxxx where x is a single digit. If so, it will set UFID accordingly. Otherwise, give a message and do not change the UFID.
SetDOB(String dob) will check whether the input String is in the format of MM/DD/YYYY and also with valid date. E.g., 02/30/1999 is not a valid date since February does not have 30 days, while Feb 12, 1999 is not a valid format. You should allow user to input date without unnecessary 0 in it, e.g., 2/3/1999 is valid.
A set of Get methods to retrieve the name/UFID/DOB info.
A public method toString() returns a String in the following format:
Name: Last name, first name
UFID: xxxx-xxxx
D.O.B: MM/DD/YYYY
Create a test class. It will read in students' info from a file. The first line of the file contains a number indicating how many students information are specified in the file. And the rest in the file contains information of each individual student. The test class will receive the name of the file through command line argument, create an array to store students info, read in the information from the file, and print out these students' info via calling the toString method.
Explanation / Answer
public class Student { private String name; private int UFID; private String DOB; private static int number; //Constructors Student(String name, int UFID, String DOB) { this.name = name; this.UFID = UFID; this.DOB = DOB; } //Get and set methods for all properties public String getName() { return name; } public void setName(String newName) { name = newName; } public int getUFID() { return UFID; } public void setUFID(int newUFID) { UFID = newUFID; } public String getDOB() { return DOB; } public void setDOB(String newDOB) { DOB = newDOB; } }