问题描述
我是 Java 新手,正在从事银行账户项目。要求是使用 MVC 架构制作控制台应用程序。我之前将 MVC 用于 Web 应用程序,但不确定它如何用于控制台应用程序。如果有人可以提供有关结构的反馈,那将非常有帮助。此外,我创建了一个 fundTransfer 方法,但每当我运行该程序时,它都不会更新现有余额。我知道我可能会遗漏一些东西,但我迷失了我在这里遗漏的东西。我在下面附上了一些片段来显示问题。欢迎大家到我的github了解整个项目并在那里进行批评。 Github bank core java console app
SavingsAccount 模型的片段如下所示:
public class SavingsAccount implements Account {
private String userId;
private String stringAccountBalance;
private String stringFundsTransfer;
public ArrayList<String> transactions;
private BigDecimal bigDecimalAccountBalance = BigDecimal.ZERO;
private BigDecimal bigDecimalFundsTransfer= BigDecimal.ZERO;
public Map<String,SavingsAccount> savingsAccountMap;
public SavingsAccount() {
savingsAccountMap = new HashMap<String,SavingsAccount>();
}
public SavingsAccount(Customer newCustomer) {
transactions = new ArrayList<String>(5);
addTransaction("Initial Deposit: " + newCustomer.initialDeposit);
}
public SavingsAccount(String userId) {
this.userId = userId;
}
public SavingsAccount(String userId,String stringAccountBalance,String stringFundsTransfer) {
this.userId = userId;
this.stringAccountBalance = stringAccountBalance;
this.stringFundsTransfer = stringFundsTransfer;
}
控制器类的片段如下所示:
public static Customer customer = new Customer();
public static SavingsAccount savingsAccount = new SavingsAccount();
...
SavingsAccount newAccount = new SavingsAccount(userId);
savingsAccount.savingsAccountMap.put(userId,newAccount);
...
if (customer.customerMap.containsKey(userId)) {
Customer newCustomer = customer.customerMap.get(userId);
savingsAccount = new SavingsAccount(newCustomer);
public static void fundsTransfer(Customer newCustomer) throws InterruptedException {
printBox("Welcome to the Funds Transfer Portal");
Scanner scan = new Scanner(system.in);
String userId = "";
String fundsTransfer = "";
System.out.print("Enter payee user Id : ");
userId = scan.next();
scan.nextLine();
System.out.println("Enter amount : ");
fundsTransfer = scan.nextLine();
if((Double.parseDouble(fundsTransfer)) > 300000)
{
System.out.println("Transfer limit exceeded. Contact bank manager.");
return;
}
if (customer.customerMap.containsKey(userId)) {
Customer payee = customer.customerMap.get(userId);
SavingsAccount payeeAccount = new SavingsAccount(payee);
payeeAccount.depositFunds(fundsTransfer);
savingsAccount.withdrawFunds(fundsTransfer);
System.out.print("\nFunds transferred successfully \nUpdated Balance for the payee: " + Double.sum(payee.initialDeposit,Double.parseDouble(payeeAccount.getBalance())) +
"\nUpdated Balance for the payer: " + Double.sum(newCustomer.initialDeposit,Double.parseDouble(savingsAccount.getBalance())) + "\n");
savingsAccount.addTransaction(savingsAccount.getBalance() + " transferred from your account.");
} else {
System.out.println("User Id doesn't exist.");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)