问题描述
今天博主在做题过程中,碰到了java.util.NoSuchElementException这个异常,说实话之前真的没见过。话不多说,先上源码
import java.util.Scanner;
public class StaticTest1 {
public static void main(String[] args) {
BankAccount.setInterestRate();
BankAccount.setMinimumBalance();
BankAccount b1 = new BankAccount("123", 400);
BankAccount b2 = new BankAccount("abc", 500);
BankAccount b3 = new BankAccount("AAA", 1000);
b1.getInfo();
b2.getInfo();
b3.getInfo();
}
}
class BankAccount {
private int id; // 账号
private String password; // 密码
private double balance; // 存款余额
private static double interestRate; // 利率
private static double minimumBalance; // 最小余额
private static int init = 1001;
public BankAccount() {
this.id = init++; // 当创建一个用户时,自动赋值ID
}
public BankAccount(String password, double balance) {
this();
this.password = password;
this.balance = balance;