I'm having trouble with a few parts of this assignment. Firstly, I dont fully grasp the purpose of a file. What does a file do? Why should I use a file? And more importantly, how do I create a file?
Second, I'm not sure how to allow the user to enter a date without unnecessary zeros.
And third, I don't know of an efficient way to chek that the date and UFID are in the proper format. I figured out a way for the UFID but I know I made it more complicated than it should be. I checked that the UFID was of the correct length, that a "-" was in the middle, and counted that the rest of the characters were digits. I know it's not the best way but I don't know how else to do it. We are still on such an elementary level in class that we can't use tools such as SimpleDateFormat and the likes.
I know that was a lot to ask, but If anyone can guide me in the right direction I would be greatly appreciative!
Part I: (30 pts) 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
Part II: (20 pts) 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.
You need to submit a zip file contains the two class files and also student info file.
This is how I checked for the validity of the UFID.
A program can get input from many different places. The user may have to type stuff in. There could be a connection to a database. There could be a socket connection to a different computer. Or, it can read from a file (and yes, there are other ways as well).
I imagine your professor wants to run several test cases through each students program. So, he (or she) has a file with various cases. When you submit your assignments, he will run his file into each and every program turned in and validate the output. It's a quick and easy way to get an idea how well you programs work.
So how do you create it? The same way you create any text file. Notepad works great.
as to question #2, How are you FORCING the user to input zeros? Note that there is a difference between GETTING the input and VALIDATING the input.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors