У меня есть проблема в моем коде, когда мои входные данные не печатаются правильно. Программа просит пользователя ввести начальный баланс каждой учетной записи. Однако, когда этот ввод распечатывается, два значения всегда печатаются одинаково. Независимо от того, что я ввожу для первой учетной записи, она всегда будет распечатывать то же значение, что и ввод для второй учетной записи. Программа должна распечатывать отдельные значения, которые были введены для каждой учетной записи.
Кроме того, программа не выводит правильные значения для рассчитанных процентов после их начисления. Я просмотрел код и не нашел ошибок. Любая помощь будет принята с благодарностью.
Входные данные:
Enter the customer’s full name: John
Enter the number of years: 4
Enter initial balance for the saving account: 10000.05
Enter initial balance for the check account: 20000.00
Ожидаемый результат:
==========================================
Initial account balances
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $10000.05
Check 2.10% $20000.00
==========================================
==========================================
Final account balances after 4 years
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $11250.87
Check. 2.10% $21750.98
==========================================
Мой результат:
==========================================
Initial account balances
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $20000.0
Check 2.10% $20000.0
==========================================
==========================================
Final account balances after 4 years
==========================================
John’s Account Rate Balance
==========================================
Saving 2.95% $22501.623657381748
Check. 2.10% $24471.619413096105
==========================================
Вот мой код:
импорт java .util.Scanner;
class Account{
private static double balance;
private static int NUM_COMPOUND_TIMES = 12;
Account(double Balance) { //constructor with parameter
balance = Balance;
}
public double getInitialBalance(){ //get the initial balance method
return balance;
}
public double getFinalBalance(double rate, int numYears) { //get the final balance method
balance = getInitialBalance()*Math.pow((1+(rate/NUM_COMPOUND_TIMES)), (NUM_COMPOUND_TIMES*numYears));
return balance;
}
}
class Customer{
private String customerName;
private static Account checkAccount;
private static Account savingAccount;
public Customer(String custName, Account savingAcc, Account checkAcc){ //constructor with parameters
customerName = custName;
savingAccount = savingAcc;
checkAccount = checkAcc;
}
public Account getSavingAccount(){
return savingAccount;
}
public Account getCheckAccount() {
return checkAccount;
}
public String getCustomerName() {
return customerName;
}
}
public class Bank {
private static Customer customerObj;
private static int numYears;
private static double INTEREST_SAVING;
private static double INTEREST_CHEQUE;
public static void main(String[] args) {
createCustomerAccounts();
printInitialBalances();
printFinalBalances();
}
public static void createCustomerAccounts() {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the customer's full name: ");
String custName = keyboard.nextLine();
System.out.println("Enter the number of years: ");
numYears = keyboard.nextInt();
System.out.println("Enter initial balance for the savings account: ");
double ibSavings = keyboard.nextDouble();
System.out.println("Enter initial balance for the cheque account: ");
double ibCheck = keyboard.nextDouble();
keyboard.close();
Account savingAcc = new Account(ibSavings);
Account checkAcc = new Account(ibCheck);
customerObj = new Customer(custName, savingAcc, checkAcc);
}
public static void printInitialBalances() {
System.out.println("==========================================");
System.out.println("Initial account balances");
System.out.println("==========================================");
System.out.println(customerObj.getCustomerName() + "'s Account Rate Balance");
System.out.println("==========================================");
System.out.println("Saving 2.95% " + "$" + customerObj.getSavingAccount().getInitialBalance());
System.out.println("Check 2.10% " + "$" + customerObj.getCheckAccount().getInitialBalance());
System.out.println("==========================================");
}
public static void printFinalBalances() {
INTEREST_SAVING = customerObj.getSavingAccount().getFinalBalance(0.0295,numYears);
INTEREST_CHEQUE = customerObj.getCheckAccount().getFinalBalance(0.0210,numYears);
System.out.println("==========================================");
System.out.println("Final account balances after " + numYears + " years");
System.out.println("==========================================");
System.out.println(customerObj.getCustomerName() + "'s Account Rate Balance");
System.out.println("==========================================");
System.out.println("Saving 2.95% " + "$" + INTEREST_SAVING);
System.out.println("Check 2.10% " + "$" + INTEREST_CHEQUE);
System.out.println("==========================================");
}
}