A friendly place for programming greenhorns!
Create a class called BankAccount in Java to hold
Hello,
i am creating a class called BankAccount and kind of stuck on a park. Question is :: I am stuck figuring out the savings account part...been at it for hours and no luck. Can any one help or guide me to finish how to do this...Ty much

Create a class called BankAccount in Java to hold
-Balance
-Number of deposits this month.
-Number of withdrawals.
-Annual Interest rate.
-Monthly charges.

The class should have following methods.

-Constructor (should accept arguments for balance and annual interest rate)

-deposit

-withdraw

-calcInterest(Formulas are Monthly Interest Rate=Annual Interest Rate/12 ,Monthly Interest = Balance * Monthly Interest Rate , Balance = Balance + Monthly Interest)

-monthlyProcess.(method that subtracts monthly service charge from balance,calls calcInterest method and sets the variable that hols number of withdrawals,number of deposits & monthly service charges to 0.

Next,design a SavingsAccount class that extends the BankAccount class. This account should have a status field which represents an active or inactive account.If the balance of saving account falls below \$25 account becomes inactive.(No withdrawals allowed until balance is above \$25 at which the account becomes active when balance is above \$25)
Savings Account should have following methods.

-withdraw (A method that determines whether account is active or inactive.No withdrawal allowed if account is inactive.A withdrawal is then made by calling the superclass version of the method)

-deposit ( Method which checks account is active or inactive..If balance greater than \$25 account becomes active.A deposit is then made by calling superclass version of method)

-monthlyProcess before the superclass method is called,, this method checks the number of withdrawals . if the no of withdrawals for the month is greater than 4,a service charge of 1\$ for each withdrawal above 4 is added to superclass field that holds the monthly service charges.(don,t forget to check the account balance after the service charge is taken . If the account falss below \$25 , the account becomes inactive))

Here is what i have for code so far. Help would be really appreciated!
import java.util.Scanner;

public class BankAccount
{
public static void main(String[] args){
System.out.println("Welcome to the bank! What do you want to do?");

}
public double balance = 0.0;
public int deposits = 0;
public double withDrawals = 0;
public double annualInterestRate = 0;
public double serviceCharge = 1;

// The constructor to hold balance and Annual Interest Rate
public double accountBalance(double bal, double intRate)
{
balance = bal;
annualInterestRate = intRate;
return balance;
}

public void deposit(double amount)
{
balance +=amount;
deposits++;

}
public void withDrawal(double amount)
{
balance -= amount;
withDrawals++;
}

private void calcInterest()
{
double monthlyInterestRate;
double monthlyInterest;

monthlyInterestRate = (annualInterestRate / 12);
monthlyInterest = balance * monthlyInterestRate;
balance = balance + monthlyInterest;
}

protected void monthlyProcess()
{
balance -= serviceCharge;
calcInterest();
withDrawals = 0;
deposits = 0;
serviceCharge = 0;
}

public double getBalance()
{
return balance;
}

}

And then the SavingAccount
public class SavingsAccount extends BankAccount
{

public SavingsAccount(double balance, double annualInterestRate)
{
super();

}

public void withDrawal(double amount)
{
if(balance >= 25)
super.withDrawal(amount);
else
System.out.println("Your account is inactive. Your balance needs to be over \$25." );
}

public void deposit(double amount)
{
if(balance >= 25)
super.deposit(amount);
else
System.out.println("Your account is inactive. Your balance needs to be over \$25." );
}

protected void monthlyProcess()
{
if(withDrawals > 4)
serviceCharge++;
else;
}
}
Thanks
Hi Tayaba.

So, what are you stuck on?

Note that people are more likely to help you if you put your code in code tags. When you make a post, just highlight all your code and press the code button in the formatting options. You can edit your post and do it now.
I trust that this is not your complete code; if so you are focusing on the wrong thing(s) first. My suggestion would be to finish the deposit object first, then on to the withdrawal and only then tackle the savings accrual and such. I'd guess that by the time you got one of those two completely working you will know what you need to finish up the bits you are stuck on.

I won't chastise you on the code blocks thing, but I will suggest that you read the FAQ before posting your upgraded code, and the next part of your question. Each first post, the poster needs to be shown the FAQ and reminded about the code blocks. Policy here is not to provide you with the code you want/need. As others will surely tell you, we will bend over backwards to offer you help and point you in the direction of how to fix the issue. We are (usually) happy to look through your solution and offer further suggestions.

And as Stephan asked, what specific problem(s) are you having? You have your formulas. You know what your inputs are, what your outputs should be.
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
RavenDB is an Open Source NoSQL Database thatâ€™s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database

This thread has been viewed 15420 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 16, 2019 15:15:41.