Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I need help with an assignment. could anyone walk me through this or give me an example to help.. I have no idea what I'm doing

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help with an assignment. could anyone walk me through this or give me an example to help.. I have no idea what I'm doing

    Create a class called BankAccount. The BankAccount class should contain a String to store the customer name and a double to store the account balance. The BankAccount class should have two constructors, as follows:

    public BankAccount(String name, double balance)
    throws NegativeAmountException
    {
    // set name and balance
    // make sure balance is not negative
    // throw exception if balance is negative
    }
    public BankAccount(String name)
    throws NegativeAmountException
    {
    // set name and use 0 balance
    }

    As can be seen, the first constructor throws a NegativeAmountException if the balance being used to create the bank account is negative. You will have to create this exception class yourself.

    The BankAccount class should also contain methods to make a deposit, make a withdrawal, get the current balance, and print a bank account statement. The interfaces for these methods should appear as follows:

    // update balance by adding deposit amount
    // make sure deposit amount is not negative
    // throw exception if deposit is negative

    public void deposit(double amount) throws NegativeAmountException
    // update balance by subtracting withdrawal amount
    // throw exception if funds are not sufficient
    // make sure withdrawal amount is not negative
    // throw NegativeAmountException if amount is negative
    // throw InsufficientFundsException if balance < amount

    public void withdraw(double amount)
    throws InsufficientFundsException, NegativeAmountException
    // return current balance

    public double getBalance()
    // print bank statement including customer name
    // and current account balance
    public void printStatement();

    Use the BankAccount class as the superclass for a SavingsAccount class. In addition to the behaviors of a BankAccount, a SavingsAccount also accumulates interest; therefore, the SavingsAccount class contains a double that is populated with the current interest rate. In addition to its constructors (you decide what the constructors should be), the SavingsAccount class should contain the following methods:

    // post monthly interest by multiplying current balance
    // by current interest rate divided by 12 and then adding
    // result to balance by making deposit

    public void postInterest()
    // print bank statement including customer name
    // and current account balance (use printStatement from
    // the BankAccount superclass)
    // following this also print current interest rate

    public void printStatement()

    Once these two classes are completed, create a driver class called Main containing a main method that tests the SavingsAccount class. Within the driver test class, create a SavingsAccount object and then use it to make deposits and withdrawals, and to post the monthly interest.

    To make the program simpler, you can incorporate the initial data for the Savings Accounts directly in the program (e.g., no need to prompt for the account holder name or starting balance). The only things you need to prompt for are the deposit amount and the withdrawal amount. Also, to simplify the task, the only exceptions that you should handle are the NegativeAmountException and the InsufficientFundsException. If either of these exception conditions occurs, print an appropriate error message and terminate the application. You can simply re-throw any IOExceptions from the main.

    there needs to be five java files. NegativeAmountException, InsufficientFundsException, BankAccount class, SavingsAccount class, and a driver class Main.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need help with an assignment. could anyone walk me through this or give me an example to help.. I have no idea what I'm doing

    Do you have some specific questions about the assignment?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Start by defining the skeleton for the class and giving it the variables that are clearly indicated in the instructions.
    Then pick one method and work on that. Design it code it, compile it, execute it and when it tests ok, move to the next method,
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: I need help with an assignment. could anyone walk me through this or give me an example to help.. I have no idea what I'm doing

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

Similar Threads

  1. Replies: 3
    Last Post: February 13th, 2014, 04:39 AM
  2. I don't know how to do this code.. Im a beginner. Can someone walk me through this?
    By ForgottenJavaKid in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 15th, 2013, 06:25 PM
  3. Replies: 1
    Last Post: December 13th, 2012, 08:47 PM
  4. Replies: 1
    Last Post: December 5th, 2012, 10:58 PM
  5. Need urgent help in assignment of JAVA, any idea suggestion plz
    By aesthete in forum Java Theory & Questions
    Replies: 2
    Last Post: January 6th, 2011, 05:58 AM