10-01-2013 - HW

posted Oct 1, 2013, 8:10 AM by Samuel Konstantinovich   [ updated Oct 2, 2013, 10:25 AM ]
Day 1 Lab + Homework
1. Define class BankAccount with these attributes and methods:
2. Include appropriate heading and comments. Put it in your dropbox folder tonight.

Instance Variables:
account holder’s full name
account password
4-digit PIN
9-digit account number
account balance

Methods for:
setting each attribute
converting all of an account’s info into a string.
depositing money
withdrawing money

Tips/Guidelines:
Select an appropriate data type for each task. Aim for efficiency.
Test, test, TEST! Develop one bit of functionality at a time. Test it, then move on.

Day 2 10-02-2013
You should have the following methods already:

BankAccount(name,account,PIN,password,balance)
BankAccount()
deposit()
withdraw()
setPIN()
setPassword()
setName() 
setAccount() 
setBalance()
toString() the format should be somehting easy to read like:

Account Holder: Bruce Leeroy
Account #: 123456789
PIN: 1234
password: shogun
balance: 1337.00

1. Place your name/period as a block comment at the top of the file. 

2. Modify your BankAccount class with these new rules: (Think about how you made your class, and if your design makes these changes easier or more difficult)

  • The account number should be an integer and it should only be set to a 9 digit number (some value between 100000000 and 999999998), if the parameter is invalid, set the account number to 999999999 and print a message to the screen about the problem.
  • The PIN should only be set to a n integer that is 4 digits number (some value between 1000 and 9998), if the parameter is invalid, set the PIN to 9999 and print a message to the screen about the problem.
  • Change withdraw so that if the account does not have enough money OR the parameter is negative: a) nothing is changed, b) an error message is printed and c) false is returned. If the account does have enough money, then the amount is deducted and true is returned.
  • Change deposit so that when the parameter is negative: a) nothing is changed, b) an error message is printed, and c) false is returned. Otherwise deposit the money and return true.
  • Write an authenticate method that takes as parameters an account number and a password, and returns true if the two match the BankAccount object and false otherwise.

3. Write a main() method as the last method in your class. Use it to test all of your methods via terminal output.

4. Place the completed file on the dropbox in a folder caled HW4.

Comments