Results 1 to 2 of 2

Thread: JAVA Help

  1. #1
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Post JAVA Help

    Hello All,

    I am new to java and need some help. I will try to program myself but need some help with psuedocode below -

    Can Someone tell me how do i link BankAccount class with Checking and Savings class


    Write a bank account program that handles bank account balances for an array of bank accounts. There are two types of bank accounts ─ checking and savings.



    Implement the following classes and methods.

    BankAccount class:

    Instance variable:
    balance

    deposit method ─ add the given amount to the current balance.

    withdraw method ─ subtract the given amount from the current balance. Don’t allow the balance to go below zero. If the balance does go below zero, change the balance to zero.

    display method ─ This must be an abstract method.

    Checking class:

    No new instance variables.

    writeACheck method ─ subtract the given amount from the current balance and then subtract an additional $1 as part of a service fee.

    display method ─ print the type of account, checking, and then the balance (with standard currency format). Study the output for details.

    Savings class:

    Instance variable:
    intRate (interest rate)

    addInterest method ─ calculate the interest by multiplying the intRate by the current balance. Add the interest to the balance.

    display method ─ print the type of account, savings, and then the balance (with standard currency format).

    Provide appropriate constructors and additional methods as necessary. Study the given main method and output for details. Hint: Don’t allow the balance to go below zero. If the balance does go below zero, change the balance to zero.

    Provide a driver class that tests your three classes. Your driver class should contain this main method:

    public static void main(String[] args)
    {
    BankAccount[] accounts = new BankAccount[100];

    accounts[0] = new Savings(1100, .05);
    accounts[0].deposit(100);
    accounts[0].withdraw(200);
    ((Savings) accounts[0]).addInterest();

    accounts[1] = new Checking(-100);
    accounts[1].deposit(50);

    accounts[2] = new Checking(200);
    accounts[2].withdraw(210);
    accounts[2].deposit(100);
    ((Checking) accounts[2]).writeACheck(50);

    for (int i=0; i<accounts.length && accounts[i] != null; i++)
    {
    accounts[i].display();
    }
    } // end main

    Output:

    Savings account balance = $1,050.00
    Checking account balance = $50.00
    Checking account balance = $49.00
    Last edited by smarty84handsome; 12-05-2013 at 05:14 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: JAVA Help

    how do i link BankAccount class with Checking and Savings class
    Both those classes extend the BankAccount class. All the methods and variables of the BankAccount class are part of both those classes.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •