* scanner.next(); */
System.out.println(\ to = scanner.nextLong();
System.out.println(\ money = scanner.nextDouble(); boolean flg = false;
for (Account a : setAcc) { if (from.equals(a.getId()) && passwordFrom.equals(a.getPassword())) { if (a.withdraw(money) != null) { for (Account b : setAcc) {
if (to.equals(b.getId())) { b.deposit(money);
String str = setAcc.toString(); File file = creatFile(); writeFile(file, str);
System.out.println(\交易成功\ flg = true; break; } } } } }
if (flg == false) {
System.out.println(\交易失败\ }
choose(from, passwordFrom); return false; }
// 贷款
public Account requestLoan(Long id, double money) { String str = null;
Scanner scanner = new Scanner(System.in); System.out.println(\ money = scanner.nextDouble(); boolean flg = false;
for (Account a : setAcc) { if (id.equals(a.getId())
&& (a instanceof LoanSavingAccount LoanCreditAccount)) {
a.setLoanAmount((long) money); str = setAcc.toString();
a instanceof || File file = creatFile(); writeFile(file, str);
System.out.println(\交易成功\ str = a.getPassword(); flg = true; break; } }
if (flg == false) {
System.out.println(\交易失败\ }
choose(id, str); return null; }
// 还贷款
public Account payLoan(Long id, double money) { String str = null;
Scanner scanner = new Scanner(System.in); System.out.println(\ money = scanner.nextDouble(); boolean flg = false;
for (Account a : setAcc) { if (id.equals(a.getId())
&& (a instanceof LoanSavingAccount || a instanceof LoanCreditAccount)) {
if (a.withdraw(money) != null) {
a.setLoanAmount(a.getLoanAmount() - (long) money); str = setAcc.toString(); File file = creatFile(); writeFile(file, str);
System.out.println(\交易成功\ str = a.getPassword(); flg = true; break; } } }
if (flg == false) {
System.out.println(\交易失败\ }
choose(id, str); return null; }
// 设置透支额度
private Account updateCeiling(Long id, String password, double money) { Scanner scanner = new Scanner(System.in); System.out.println(\ money = scanner.nextDouble(); boolean flg = false;
for (Account a : setAcc) {
if ((a instanceof CreditAccount || a instanceof LoanCreditAccount && id.equals(a.getId()))
&& password.equals(a.getPassword())) { ((CreditAccount) a).setCeiling(money); String str = setAcc.toString(); File file = creatFile(); writeFile(file, str); flg = true; break; } }
if (flg == false) {
System.out.println(\设置失败\ } else {
System.out.println(\设置成功\ }
choose(id, password); return null; }
// 统计银行所有账户余额总数 public double amount() { double amount = 0;
for (Account a : setAcc) { amount += a.getBalance(); }
return amount; }
// 统计所有信用账户透支额度总数 public double sum() { double sum = 0;
for (Account a : setAcc) {
if (a instanceof CreditAccount || a instanceof LoanCreditAccount) { sum += ((CreditAccount) a).getCeiling(); } }
return sum; }
// 统计所有账户贷款的总额 public double totoal() { double sum = 0;
for (Account a : setAcc) { sum += a.getLoanAmount(); }
return sum; }
// 打印所有用户的总资产排名 public void totalAssets() {
Account[] a = setAcc.toArray(new Account[setAcc.size()]);
for (int i = 0; i < a.length; i++) { double sum = 0;
for (int j = 0; j < a.length; j++) {
if (a[i].getPersonId().equals(a[j].getPersonId())) { if (j < i) {
a[i].setId(0l); ;
break; } else {
sum += a[j].getBalance(); a[i].setBalance(sum); } } } }
for (int i = 0; i < a.length; i++) { Account acc;
for (int j = i + 1; j < a.length; j++) {
if (a[i].getBalance() < a[j].getBalance()) { acc = a[i]; a[i] = a[j]; a[j] = acc; } } }
for (int i = 0; i < a.length; i++) { if (a[i].getId() != 0) {
System.out.println(a[i]);
} } } }
4.3 接口
package ATM_Bank;
public interface Loanable { //贷款
public abstract Account requestLoan(double money); //还贷
public abstract Account payLoan(double money); }
4.4 测试类
package ATM_Bank;
public class Test {
public static void main(String[] args) { String str = \ System.out.println(str.length()); Bank bank = new Bank();
bank.register(null, null, null, null, null, null, 0); bank.amount(); } }
4.5 运行结果
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库张迪的课程设计报告(6)在线全文阅读。
相关推荐: