x.Hm reason I get error on this program, can someone help by compiling the progr
ID: 3617161 • Letter: X
Question
x.Hm reason I get error on this program, can someone help by compiling the program and fixing the error. there are two programs since it is about inheritance. The first one gives one error/ the second one gives four (The question is posted at the bottom of the page if you want to take a look at it)First Program:
public class BankAccount { private static int nextAccountNumber = 10000; private static double currentInterestRate = 0.05; public static void setCurrentRate(double newRate) { currentInterestRate = newRate; } private int accountNumber; private double balance; private double rate; public Account(double initialBalance) { accountNumber = nextAccountNumber++; balance = initialBalance; rate = currentInterestRate; } public int getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double getRate() { return rate; } public double getCurrentRate() { return currentInterestRate; } public void deposit(double amount) { balance += amount; } public boolean withdraw(double amount) { if (amount > balance) // refuse to let account be overdrawn { return false; } else { balance -= amount; return true; } } public void updateRate() { rate = currentInterestRate; } public void elapse(int numberOfDays) { for (int day = 1; day <= numberOfDays; ++day) { balance += balance * rate / 12; } } }
Second Program:
public class SavingAccount extends BankAccount { public boolean withdraw(double amount) { if (getbalance()>= amount+minAmount) { super.withdraw(amount); return true; } else return false; } private double minAmount; }
private intnumberOfWithdrawals; public SavingsAccount () { balance = 0; numberOfWithdrawals = 0; } public voidwithdraw (intamount) { if (numberOfWithdrawals > 4) { throw newRuntimeException ("If the withdrawls >4 a service charge of 1$ is charged"); } else { balance = balance -amount; numberOfWithdrawals++; } } public voidresetNumOfWithdrawals () {} }
The Question: 1)Design a class named BankAccount to hold the following data for a bank account:
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method,
First Program:
public class BankAccount { private static int nextAccountNumber = 10000; private static double currentInterestRate = 0.05; public static void setCurrentRate(double newRate) { currentInterestRate = newRate; } private int accountNumber; private double balance; private double rate; public Account(double initialBalance) { accountNumber = nextAccountNumber++; balance = initialBalance; rate = currentInterestRate; } public int getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double getRate() { return rate; } public double getCurrentRate() { return currentInterestRate; } public void deposit(double amount) { balance += amount; } public boolean withdraw(double amount) { if (amount > balance) // refuse to let account be overdrawn { return false; } else { balance -= amount; return true; } } public void updateRate() { rate = currentInterestRate; } public void elapse(int numberOfDays) { for (int day = 1; day <= numberOfDays; ++day) { balance += balance * rate / 12; } } }
Second Program:
public class SavingAccount extends BankAccount { public boolean withdraw(double amount) { if (getbalance()>= amount+minAmount) { super.withdraw(amount); return true; } else return false; } private double minAmount; }
private intnumberOfWithdrawals; public SavingsAccount () { balance = 0; numberOfWithdrawals = 0; } public voidwithdraw (intamount) { if (numberOfWithdrawals > 4) { throw newRuntimeException ("If the withdrawls >4 a service charge of 1$ is charged"); } else { balance = balance -amount; numberOfWithdrawals++; } } public voidresetNumOfWithdrawals () {} }
The Question: 1)Design a class named BankAccount to hold the following data for a bank account:
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method, public class BankAccount { private static int nextAccountNumber = 10000; private static double currentInterestRate = 0.05; public static void setCurrentRate(double newRate) { currentInterestRate = newRate; } private int accountNumber; private double balance; private double rate; public Account(double initialBalance) { accountNumber = nextAccountNumber++; balance = initialBalance; rate = currentInterestRate; } public int getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double getRate() { return rate; } public double getCurrentRate() { return currentInterestRate; } public void deposit(double amount) { balance += amount; } public boolean withdraw(double amount) { if (amount > balance) // refuse to let account be overdrawn { return false; } else { balance -= amount; return true; } } public void updateRate() { rate = currentInterestRate; } public void elapse(int numberOfDays) { for (int day = 1; day <= numberOfDays; ++day) { balance += balance * rate / 12; } } }
Second Program:
public class SavingAccount extends BankAccount { public boolean withdraw(double amount) { if (getbalance()>= amount+minAmount) { super.withdraw(amount); return true; } else return false; } private double minAmount; }
private intnumberOfWithdrawals; public SavingsAccount () { balance = 0; numberOfWithdrawals = 0; } public voidwithdraw (intamount) { if (numberOfWithdrawals > 4) { throw newRuntimeException ("If the withdrawls >4 a service charge of 1$ is charged"); } else { balance = balance -amount; numberOfWithdrawals++; } } public voidresetNumOfWithdrawals () {} }
The Question: 1)Design a class named BankAccount to hold the following data for a bank account:
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method, public class SavingAccount extends BankAccount { public boolean withdraw(double amount) { if (getbalance()>= amount+minAmount) { super.withdraw(amount); return true; } else return false; } private double minAmount; }
private intnumberOfWithdrawals; public SavingsAccount () { balance = 0; numberOfWithdrawals = 0; } public voidwithdraw (intamount) { if (numberOfWithdrawals > 4) { throw newRuntimeException ("If the withdrawls >4 a service charge of 1$ is charged"); } else { balance = balance -amount; numberOfWithdrawals++; } } public voidresetNumOfWithdrawals () {} }
The Question: 1)Design a class named BankAccount to hold the following data for a bank account:
- Balance
- Number of deposits this month
- Number of withdrawals
- Annual Interest rate
- Monthly service charges
The class should have the following methods:
Constructor : The constructor should accept aruguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit.The method should add the argument to the account balanc.
It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of withdrawal.The method should substract the argument from the balance.
It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account,and adding this interest earned by the account,
and adding this interest to the balance.This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest =Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
montlyProcess: A method that substracts the montly service charges from the balance,calls the calcInterest method,
Explanation / Answer
class BankAccount { private static intnextAccountNumber = 10000; private static doublecurrentInterestRate = 0.05; public static voidsetCurrentRate(double newRate) { currentInterestRate = newRate; } private int accountNumber; private double balance; private double rate; public BankAccount(double initialBalance) { accountNumber =nextAccountNumber++; balance = initialBalance; rate = currentInterestRate; } public int getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double getRate() { return rate; } public double getCurrentRate() { return currentInterestRate; } public void deposit(doubleamount) { balance += amount; } public boolean withdraw(double amount) { if (amount > balance) // refuse tolet account be overdrawn { return false; } else { balance -= amount; return true; } } public void updateRate() { rate = currentInterestRate; } public void elapse(intnumberOfDays) { for (intday = 1; day =amount+minAmount) { super.withdraw(amount); return true; } else return false; } private double minAmount; privateint numberOfWithdrawals; publicSavingAccount () { super(0); numberOfWithdrawals= 0; } publicvoid withdraw (int amount) { if (numberOfWithdrawals > 4) { throw newRuntimeException ("If the withdrawls >4 a service charge of 1$ ischarged"); } else { super.withdraw(amount); numberOfWithdrawals++; } } publicvoid resetNumOfWithdrawals () {} }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.