Question: Using java 1. Create a Student class with member variables for Name and ID. Both member variables should be of type String. The constructor should
Using java
1. Create a Student class with member variables for Name and ID. Both member variables should be of type String. The constructor should take the name and id as Strings. Create getter methods for the member variables.
2. Create an InvalidIdException class that extends Exception and yields the message ID must be an integer between 1-1000.. Be sure to follow the guidelines on Day 22 PPT slides 32-33 for creating exceptions. (
3. Create a class Converter with a static method called convertId that uses Integer.parseInt() to convert an ASCII string to an Integer. Converter.convertId should test for the validity of the string being passed in. If the string is invalid (i.e., empty or null) convertId should throw an InvalidIdException. If parseInt throws an exception due to invalid input (i.e., a non-numeric value is passed in such as xyz) convertId should catch the exception thrown by parseInt and then throw the InvalidIdException.
4. Create an InvalidNameException class that extends Exception and yields the message, Name must be composed of 1-25 ASCII characters.
5. Update the constructor of the Student class to throw an InvalidNameException if the name passed in is not a valid name: The following checks must validate the name:
? The string must not be null.
? The string must not be empty ( ).
? The string must contain only ASCII letters A-Z or a space
? The string must be between 1-25 characters long. If the string does not meet all of the above criteria, the constructor of Student should throw the InvalidNameException
6. Update the constructor of the Student class to throw an InvalidIdException if the ID passed in is not a valid ID. The following checks must validate the ID:
? The id must not be null.
? The id must not be empty ( ).
? The id must be numeric. (Hint, use parseInt() but catch the exception thrown by parseInt().)
? The id must be <= 10000.
If the string does not meet all of the above criteria, the constructor of Student should throw the InvalidIdException.
7. Create a class called StudentHash that implements a HashSet. (i.e., HashSet) This will require Student to provide implementations of HashCode() and .equals(). HashCode should make use of the ConvertId to return an int version of StudentId.
8. StudentHash should also provide addStudent(), removeStudent() and getStudentList() per API documentation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
