小编XVS*_*Shi的帖子

如果在setter / getter中创建

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)

java getter-setter

12
推荐指数
1
解决办法
348
查看次数

标签 统计

getter-setter ×1

java ×1