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,and then sets the variables that hold
the number of withdrawls,number of deposits,and monthly services to zero.

Next,design a SavingAccount class that extends the BankAccount class.
The SavingsAccount class should have a status field to represent an acctive or inactive account.
If the balance of a savings account falls below $25,it becomes inactive.
(The status field could be a boolean variable.)No more withdrawals may be made until the balance is raised above $25,at which time the account becomes active again.

The savings account class should have the following methods:

withdraw: A method that determines whether the account is inactive before a withdrawal is made.
(No withdrawal will be allowed if the account is not active.)A withdrawal is then made by calling the superclass version of the method.

deposit : A method that deterines whether the account is inactive before a deposit is made.If the account is inactive and the deposit brings the balance abovee $25,the account becomes active agian.
A deposit is then made by calling the superclass version of the method.

monthlyProcess: Before the superclass method is called,this method checks the number of withdrawals.If the number of withdrawals for the month is more than 4,a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges.
(Don't forget to check the account balance after the service charge is taken.If the balance falls below $25,the account becomes inactive.)

*/
class is BankAccount
*/
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;
        }
    } 
}

Code tags and formatting please. Otherwise it is impossible to read. I formatted your code in NetBeans. Indentation is a must.

[code=JAVA]
paste code here
[/code]

Watch your spelling. Is it Account or BankAccount? Is it SavingAccount or SavingsAcount? Everything much match. Constructor name needs to match class name. Constructors should be INSIDE the class. Check your brackets. Also, describe what the problems are and please ask a specific question. NetBeans did its best to format SavingsAccount, but got confused due to brackets problems. Please repost corrected, formatted code in code tags, along with a particular question, including line numbers. Thanks.

@jvd401

  • Go to nearest bookshop
  • Find IT section
  • Look-up programming section
  • Find one of Java-How to Program, by Deitel, book
  • By the book
  • Start reading
  • While at break have look on following forum rule

Note: This is not my Homework or Assignment.....This is a Question for our research about java that lecturer gave us to learn more about Java....but he didn't tell the answer..told us to find out ourself...But i have tried it do this...Our Java class was only about theory....So i didn't learn about Programming in Java yet...So itz like a difficult question for me because we are only learning theory.....So it will be great if someone can help me with this...i will be grateful to u...Thnkx


__________________________________________________________________
Here is wat i did so far
I created new class called BankAccount.I did till withdraw (method) of BankAccount...but after that i have no clue how to do calcInterest and after on.....SavingsAccount
__________________________________________________________________

Question is ::

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 (This method checks the number of withdrawals.If the number 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.)

________________________

________________________
///////////Main////////////

import java.util.*;
import java.text.DecimalFormat;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        double startBalance = 0;
        double interest;
        int months;
        double deposit;
        double withdraw;


        Scanner key = new Scanner(System.in);
        //create an object that accepts the starting balance
        BankAccount account = new BankAccount(startBalance);

        DecimalFormat dollar = new DecimalFormat("#,###.00");

        System.out.println("Please enter the anual interest rate ");

        interest=key.nextDouble();

        account.setInterest(interest);

        System.out.println("Please enter the starting balance");

        startBalance=key.nextDouble();

        System.out.println("Please enter how many months has passed since the account creation ");

        months=key.nextInt();

        for (int i=1; i<=months; i++) {

        System.out.println("Please enter the amount deposited in the account during the month "+i);

        deposit = key.nextDouble();

        account.deposit(deposit);

        System.out.println("Please enter the amount to be withdraw during this month "+i);

        withdraw=key.nextDouble();

        account.withdraw(withdraw);

        //account.addmonthInt(input); //here i think there is the error
         account.addmonthInt(interest);
        }
System.out.println("Account Balance $"+dollar.format(account.getBalance()));
System.out.println("Total withdraws $"+account.totalwithdraw);
System.out.println("Total deposits $"+account.totaldeposit);
System.out.println("Total Interest Earned $"+account.earnedInt);
System.out.println("Anual int"+account.getInt());
    }

}

_________________________

class BankAccount
{
     private
            double balance;
            double anualInterest;
            double monthInt;
            double totaldeposit;
            double totalwithdraw;
            double earnedInt;
    public BankAccount(double startBalance)
            //Constructor accepting the starting balance
            {
                balance = startBalance;
            }
            public void deposit(double amount)
            {
                balance += amount;
                totaldeposit += amount;
            }
            public void withdraw(double amount)
            {
                balance -= amount;
                totalwithdraw += amount;
            }
            public void addmonthInt(double monthlyInterest)
            {
                monthInt = (anualInterest / 12);
                balance += monthInt * balance;
                earnedInt += monthInt;
            }
            public void setInterest(double i)
            //set your interest rate
            {
                monthInt = i;
            }
            public double getBalance()
            {
                return balance;
            }
            public double getInt()
            {
                return anualInterest;
            }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.