Write a program where you create a class called bankaccount

Assignment Help Programming Languages
Reference no: EM131307708

Write a program where you 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: EM131307708

Questions Cloud

Create a sales page that users see when they first access : You do not need to know HTML tags to use Web page creation tools. Typically, a professional Web site developer will create a sales page that users see when they first access the site.
Plot the output voltage of the line : The receiving gate is represented at its input by 10 pF. Because of the capacitive load, this would be a difficult problem to do by hand. Use SPICE (PSPICE) to plot the output voltage of the line, VL(t), for 0
Create diagram of dsl and cable modem connection to your isp : Create a diagram of the DSL and Cable Modem connections to your ISP, cable organization, and telecom to your home router using Visio or its open source alternative software.
Define the security strategies of defense in depth security : In this paper, you will define the security strategies of Defense in Depth and Layered Security along with comparing and contrasting the strategies by explaining.
Write a program where you create a class called bankaccount : Write a program where you 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.
What is conflict management : What is conflict management.watch the video lecture below to learn why conflict at work isn't always a bad thing.
Implement the fdtd method in a matlab program : ECE 452 - Assignment Give a FD discretization of the wave equation for an interior node (i, j) - Derive the FD equations for nodes on the left, right, top and bottom boundaries - Derive the stability condition for each of the above time discretizatio..
Find the price elasticity of demand for newtons donuts : Calculate the price elasticity of demand for Newton's Donuts and describe what it means. Describe your answer and show your calculations.
Explain effective approaches to the broad spectrum : Explain effective approaches to the broad spectrum of employee relations, including career development, fostering ethical behavior, discipline, labor relations, and dismissals.

Reviews

Write a Review

Programming Languages Questions & Answers

  Provide pseudocode of your overall design

our final project will be to analyze, design, and document a simple program that utilizes a good design process and incorporates sequential, selection and repetitive programming statements as well as function and subprogram calls and uses arrays. ..

  Create database tables in mysql

Write the SQL command to find any tutors who have not submitted a report for July

  Write application to compute the total cost of new carpet

Write the application which computes the total cost of new carpet for a rectangular room. Application must first ask user for the current cost of the carpet per square foot. It then asks for both length.

  Create a class called dateprofile

Assignment - Computer Dating, Create a class called DateProfile that has the following private instance members: gender - a char, the gender of the applicant ('M' or 'F')

  Design getter and setter and constructor methods

User must have option to draw new shape at different location and keep the existing shape. Design all the getter and setter & constructor methods for each class.

  Program with two functions to solve voting problem

Program with at least two functions to solve following problem. Members of board of small university are considering voting for pay increase for their 10 faculty members.

  Write the code for the countwords function

Write the code for the countWords function (you can assume that the line begins with a letter, that each word is separated by a single space and that the line ends with a period.

  Prepare class to include three data member

Prepare Class called Employee that includes three pieces of information as data members - first name (type string), last name (type string) and monthly salary (type float).

  Aggregate planning for a bottling companya bottling company

aggregate planning for a bottling companya bottling company has decided to introduce a new line of premium bottled

  How data can be pulled from multiple web pages

This project will show how data can be pulled from multiple web pages, show flexible programming routines, minimize screen updates, and demonstrate some mathematical functions.

  Write a program that reads in investment amount

Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value

  Write program which demands user to enter ten numbers

Write the program which demands user to enter 10 numbers (using an input box) and prints (using a message box) message ‘negative' if number is less than zero.

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