Question
The class below has encapsulation problems. Fix them! ```java public class Student{ private String firstName; private String lastName; private String studentId; } ``` ## Requirements
The class below has encapsulation problems. Fix them!
```java
public class Student{
private String firstName;
private String lastName;
private String studentId;
}
```
## Requirements
Components that you will be graded upon:
- No direct access to private data allowed from the outside
- Provide a constructor that takes studentId, firstName, and lastName IN THAT ORDER
- Allow first and last names to be read and updated.
- Do not allow student id to be changed after object construction
- As part of object construction, enforce validation so that the studentId must meet the following criteria:
- 9 characters in overall length,
- The first character is K (case sensitive)
- The second and all subsequent characters are numeric.
- If it does not meet the requirement, add the following code to the correct section of the validation:
```java
throw new Exception("Student ID must be 9 characters long, start with a K, and have seven trailing numeric characters");
```
You will also need to add the following to end of your constructor declaration:
```java
throws Exception
```
- Make sure your code compiles to get maximum partial credit even if it doesn't pass all tests
/**
* Problem1
*/
public class Problem1 implements IProblem {
public void run(){
// TODO:
// 1) Add the Student class to the same folder this file is in
// DO NOT WRITE the Student code in THIS file
// 2) Write the code to TEST the Student class in this method
// (e.g. Create an instance of Student, call its methods, etc)
}
}
public class Student{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started