Java相当新,希望在使用setter / getters并使用toString方法创建输出时存储乘客详细信息方面有所帮助。
The problem I have is, say I am storing the passengers phone number and don't want their phone number to contain any characters, have a length of 10 numbers and start with 1 and return "Not Valid" if one of these occur.
I have tried to create if statements in the setter but it is not returning the "Not Valid". This is what I have so far
public class Passenger {
private String name;
private String location; …Run Code Online (Sandbox Code Playgroud)