This is a Savings Account which a balance and monthly interest rate. the withdra
ID: 3771643 • Letter: T
Question
This is a Savings Account which a balance and monthly interest rate. the withdrawals are limited to 3 per month. If a withdrawal occures after 3 times in 30 days, there must be 2% balance penalty automatically taken out of the savings balance and show in report.
I trid but it doesn't work !!
----------------------------------------------------------------------------------------------------
package bankapp;
public class SavingAccount extends BankAccount {
// create a interest field with default value 1%
public double interest = 1.0;
public double balnace;
public String name;
public int free_withdraw_Transactions = 3;
public int withdraw_Transactions;
/**
*
*/
public double penaltyInterest = 0.2;
public String accoutType;
public int transactions[];
public String transactionsSummary[];
SavingAccount(String name, double balance, int dateCreated) {
super(name, balance);
this.accountType = "saving";
}
@Override
public double getProjectAmount()
{
return projectAmount;
}
public double getBalance()
{
return balance;
}
public void setBalance ( double val)
{
balance = val;
}
/**
* @param amount
*/
public void projectAmount( double amount)
{
double newBalance = balance * amount;
}
// conditional withdraw
//
@Override
public void withdraw( double amount)
{
if (amount <= 0) {
System.out.println("Amount should be positive");
} else { if (getBalance()<=0)
{
System.out.println("Balance should be positive");
}
else
{
withdraw_Transactions++;
double newBalance = balance - amount;
balance = newBalance;
if(withdraw_Transactions> free_withdraw_Transactions)
{
newBalance=0.0;
newBalance= (balance *penaltyInterest/100)/12;
balance = newBalance;
}
}
}
}
public void deposit ( int amount)
{
if (amount<=0)
{
System.out.println("Amount to be deposited show be positive");
}
else
{
// new balance includes interest
balance = balance+amount +((amount * interest)/100)/12;
transactions[numOfTransactions]= amount;
transactionsSummary[numOfTransactions] = "$" + Double.toString(amount)+"was deposited";
numOfTransactions++;
}
}
@Override
public String toString()
{
return " Name: " + customerName + " Balance:"+ balance + " Date:"+ dateCreated;
}
}f
Explanation / Answer
Modified Program:
// File: SavingAccount.java
package bankapp;
public class SavingAccount extends BankAccount
{
public double interest = 1.0;
public double balnace;
public String name;
public int free_withdraw_Transactions = 3;
public int withdraw_Transactions;
public double penaltyInterest = 2.0;
public String accountType;
public int transactions[];
public String transactionsSummary[];
public int numOfTransactions;
public String dateCreated;
public double projectAmount;
SavingAccount(String name, double balance, String dateCreated)
{
super(name, balance);
this.dateCreated = dateCreated;
this.accountType = "saving";
}
public double getProjectAmount()
{
return projectAmount;
}
public double getBalance()
{
return balance;
}
public void setBalance(double val)
{
balance = val;
}
public void projectAmount(double amount)
{
projectAmount = balance * amount;
}
public void withdraw(double amount)
{
if (amount <= 0)
{
System.out.println("Amount should be positive");
}
else if(getBalance() <= 0)
{
System.out.println("Balance should be positive");
}
else if(getBalance() < amount)
{
System.out.println("Insufficient balance");
}
else
{
withdraw_Transactions++;
balance = balance - amount;
if(withdraw_Transactions > free_withdraw_Transactions)
{
balance = balance - (balance * penaltyInterest / 100) / 12;
}
}
}
public void deposit(int amount)
{
if (amount <= 0)
{
System.out.println("Amount to be deposited show be positive");
}
else
{
balance = balance + amount + ((amount * interest) / 100) / 12;
transactions[numOfTransactions] = amount;
transactionsSummary[numOfTransactions] = "$ " + Double.toString(amount) + " was deposited";
numOfTransactions++;
}
}
@Override
public String toString()
{
return " Name: " + customerName + " Balance:" + balance + " Date:" + dateCreated;
}
}
// File: BankAccount.java
package bankapp;
public class BankAccount
{
public String customerName;
public double balance;
public BankAccount()
{
customerName = "";
balance = 0;
}
public BankAccount(String name, double bal)
{
customerName = name;
balance = bal;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.