CSCE 145: Lab 15
Bank Accounts

Objectives

In today's lab we'll cover

Overview

Today's lab will not involve Becker's robots. We will be developing a class that represents a bank account and a driver that interacts with the user to use the class.

Program Specification

Account

Create a class, Account, that has an instance variable "balance".   Create an accessor and mutator for the variable

Create 2 constructors: a default constructor that initializes all variables to default values and a parameterized constructor that accepts a value for "balance".

Create services "deposit" and "withdraw".  Both should accept a double argument "amount" and update balance by adding "amount" for deposit and subtracting "amount" for withdraw.

Driver

Create a driver that will allow a user to use your Account class.  Your driver should first create an account with a 0 balance.  Next, the program should ask the user what they would like to do with their account (deposit, withdraw, see their balance, or quit).  The program should perform the action, then ask the use the same question again (and again and again...), until the user chooses to quit.  The format is shown in the example below.

Example Output

Welcome to the bank account program!

What would like to do? Type "+amount" to deposit "amount" in your account, "-amount" to withdraw "amount", "balance" to see your balance, or "quit" to quit:

+250

Ok, adding $250...

What would like to do? Type "+amount" to deposit "amount" in your account, "-amount" to withdraw "amount", "balance" to see your balance, or "quit" to quit:

balance

Your current balance is $250.

What would like to do? Type "+amount" to deposit "amount" in your account, "-amount" to withdraw "amount", "balance" to see your balance, or "quit" to quit:

-300

Ok, withdrawing $300...

What would like to do? Type "+amount" to deposit "amount" in your account, "-amount" to withdraw "amount", "balance" to see your balance, or "quit" to quit:

balance

Your balance is $-50.

What would like to do? Type "+amount" to deposit "amount" in your account, "-amount" to withdraw "amount", "balance" to see your balance, or "quit" to quit:

quit

Thank you for using the program. Goodbye.

 

Show your program to your TA when you are done and submit it to the dropbox at https://cse.sc.edu.