account.java

来自「文件说明java模式」· Java 代码 · 共 51 行

JAVA
51
字号




public class Account {

  String firstName;
  String lastName;
  final String ACCOUNT_DATA_FILE = "AccountData.txt";

 //constructor
  public Account(String fname, String lname) {
    firstName = fname;
    lastName = lname;
  }

  //check if the last name is correct or not
  // the length of last name should equal to
  // or greater than 6
  public boolean isValid() {
    /*
     	Let's go with simpler validation
     	here to keep the example simpler.
     */

    if (getLastName().trim().length() < 6)
      return false;

    return true;
  }

  // save last name and first name
  public boolean save() {
    FileUtil futil = new FileUtil();
    String dataLine = getLastName() + "," + getFirstName();
    return futil.writeToFile(ACCOUNT_DATA_FILE, dataLine,
           true, true);

  }

  // get first name and last name
  public String getFirstName() {
    return firstName;
  }
  public String getLastName() {
    return lastName;
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?