creditcard.java
来自「文件说明java模式」· Java 代码 · 共 66 行
JAVA
66 行
public class CreditCard {
String cardType;
String cardNumber;
String cardExpDate;
//final String CC_DATA_FILE = "CC.txt";
final String CC_DATA_FILE = "CreditCardInfo.txt";
//constructor of CreditCard
public CreditCard(String ccType, String ccNumber,
String ccExpDate) {
cardType = ccType;
cardNumber = ccNumber;
cardExpDate = ccExpDate;
}
//check if the credit card number is valid or not
//length of number for Visa is 16
//length of number for Discover is 15
//length of number for MASTER is 16
public boolean isValid() {
/*
Let's go with simpler validation
here to keep the example simpler.
*/
if (getCardType().equals(AccountManager.VISA)) {
return (getCardNumber().trim().length() == 16);
}
if (getCardType().equals(AccountManager.DISCOVER)) {
return (getCardNumber().trim().length() == 15);
}
if (getCardType().equals(AccountManager.MASTER)) {
return (getCardNumber().trim().length() == 16);
}
return false;
}
//save credit card info to cc.txt
public boolean save() {
FileUtil futil = new FileUtil();
String dataLine =
getCardType() + "," + getCardNumber() + "," +
getCardExpDate();
return futil.writeToFile(CC_DATA_FILE, dataLine, true,
true);
}
public String getCardType() {
return cardType;
}
public String getCardNumber() {
return cardNumber;
}
public String getCardExpDate() {
return cardExpDate;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?