Create a class called bankaccount

Assignment Help JAVA Programming
Reference no: EM13881623

For your new program (#5 above), 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 FinalExam 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.

Reference no: EM13881623

Questions Cloud

Write an advanced java program for the game blackjack : Write an advanced java program for the game blackjack according to the following below data flow diagram
Reverses a three digit number producing a result : Hint.First write a static method that reverses a three digit number producing a result as described above, and test it directly from the main method. Your static method should have the following signature.
The total of the sale proceeds was credited : The total of the sale proceeds was credited to the investment account.
Calculate the heat required to raise : Calculate the heat required to raise 50 kg of solid sodium carbonate (Na2CO3) from 10°C to 50°C at 1atm using
Create a class called bankaccount : For your new program (#5 above), 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:
The investment over the book value of net assets : 1.Fizer Pharmaceutical paid $68 million on January 2, 2013, for 4 million shares of Carne Cosmetics common stock.
What is the capital recovery amount : What is the capital recovery amount? what sales price is necessary at that time (year 10) to realize the same amount as the 8% return expected over the 20-year ownership period?
A listener for the click events of a button : What happens if you fail to register an object as a listener for the click events of a button?
How is the location of the click point determined : When a mouse event is generated how is the location of the click point determined?

Reviews

Write a Review

JAVA Programming Questions & Answers

  User-defined methods

You will create the ShoutBox class for your Virtual World. Your ShoutBox class will have a shoutOutCannedMessage() method that returns a String type.

  Create a jframe that includes a jlabel that reads hello word

Design, implement, test, and debuga GUI-based version of a "Hello, World!" program. Create a JFrame that includes a JLabel that reads "Hello, World!" Use a layout manager of your choice

  Representing an investment value and interest rate

Write a Java test program, all your code should be in the main method that asks the user for two numbers representing an investment value and interest rate.

  Write the constructor date which has 3 parameters

The Date.java class. Implement a public class Date that represents a date composed of a month , day, and a year. Declare month, day, and year as integers. Date has a constructor with 3 parameters and 4 methods. Write the constructor Date which has..

  Implement a javascript program for the validation case

Write a JavaScript program for the validation case using the RegExp method - implement a JavaScript program for the validation case

  Design an adt for the problem

Design an ADT for this problem. Be sure to consider all necessary operations to maintain the appointment book for one year, to archive the yearly book and create a new book for the following year.

  A java program that will prompt the user to input a file

Write a Java program that will prompt the user to input a file (document) in order to count the frequency of each word. This program will display the frequency of each word sorted alphabetically or by frequency (depending on the preference of the use..

  Quadratic that solves quadratic equations

Write a method called quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form ax2 + bx + c = 0. The formula for solving a quadratic equation is ?..

  Write java application that effectively uses java collection

Write a Java application that effectively uses Java collections to store up to 20 instances of the Person class and its subclasses. Then write a GUI that displays the Person names using radio buttons to select a value

  Create an application with a jframe

Create an application with a JFrame that holds five labels describing reasons that acustomer might not buy your product (for instance, "Too expensive").

  Write a program that converts number from binary to decimal

write a program that Converts a Number from Binary to Decimal  by using reading keyboard input.

  List various bindings that are needed to determine semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd