Lab 10: Java Banking Account Program, Lab Reports of Computer Science

A java programming lab assignment for cis 120-101 students in the fall 2007 semester. The objective is to design and implement a 'lab10' program with a 'bankaccount' class that simulates the activities of several banking accounts with appropriate operations. Students must write the code for the 'bankaccount' class and include it within the 'lab10.java' file. The 'bankaccount' class will provide an abstraction for the 'lab10' class. The required instance and class methods, constructor specifications, and hints are provided.

Typology: Lab Reports

Pre 2010

Uploaded on 08/16/2009

koofers-user-0m8
koofers-user-0m8 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:__________________________________________________________________Section:___________
CIS 120-101 / Overstreet / Fall 2007
Lab 10 – Due: Week 12 (Wed 11/7/07)
Problem Description
Design and implement a program with a Java class called “Lab10”. Lab 10 will simulate the activities of a several banking accounts
with appropriate operations on each of those accounts. [See Program 5 description where we solved this SAME problem, but had
ONLY 1 account because the operations were on class variables. We will now redo this the right way!]
Code Requirements:
Your code must use the code provided to you on this assignment (you can access the source code for this assignment at the following
URL:<fill in with the correct URL for file> ). That code will include a main that will create and use objects of type “BankAccount”
(you will write the code for this class and will include it within the file Lab10.java (at the bottom). Yes a Java file can have more than
one class declaration in it as long as only one of them has a main-method. In this lab the Lab10 class will have a main-method and the
class definition that you write for BankAccount will not have a main-method. In essence, Lab10 is acting as a “client” of the
BankAccount class. The BankAccount class is thus providing a good abstraction for us! Your output dialogs should have your name
on them as opposed to “CIS Faculty” shown in sample output below. All of the class and instance variables in your class definition
MUST be declared as “private” (thus access to them from Lab10 will only be via the methods that you write)!
Error Checking:
The version of main that we supply should be doing this for you. If your code bombs showing any kind of error message, then you
have a fix to make. If your program produces output that differs from that shown below it is wrong.
Required Instance Methods and Their Semantics:
(1) A constructor that takes first name, last name and opening amount [positive or negative] as a starting amount. This method
sets all the needed instance variables. The account is considered “open” after this constructor call.
(2) A constructor that takes a first name, last name as its only formal parameters (the amount of initial deposit in this case is
assumed to be $0).
(3) A String method called accountOwner (with no parameters to it) that returns the owners full name with a space between the
first and last names.
(4) A version of toString that overrides the version in the class called Object. It must, of course, have a signature that looks like:
public String toString(); This method should produce a String exactly like the following:
“Bill Smith :: (Current Balance = $12.50)“
(5) A void method called deposit that takes a double amount as a parameter. This amount will be added to the dollars in the
account (and could of course influence whether it is now overdrawn or not).
(6) A void method called withdraw that takes a double amount as a parameter. This amount will be deducted from the dollars in
the account (and could of course influence whether it is now overdrawn or not).
(7) A double returning method called balance (with no parameters to it) that returns the dollars now in the account.
(8) A Boolean method called approveCheckFor with a double parameter to it that specifies some amount. If the account has
enough in it to cover a check in that amount then a true is returned, otherwise a false is returned (note that dollars in the
account is not modified by this method).
(9) A Boolean method called isNowOverdrawn (with no parameters to it) that returns a true if the account is currently
overdrawn and a false otherwise.
(10) A void method called showAccount (with no parameters to it) that will use a JOptionPane message dialog to display the
account owners full name, the account balance, and whether the account is now overdrawn or not. This method is expected
to call the accountOwner and isNowOverdrawn methods. The account balance must be shown with two digits after the
decimal point.
Required Class Method and its Semantics:
(1) A method to return the number of accounts that are now in existence. This method, called howManyAccounts, returns an int
and takes no arguments.
Hints: Comment out parts of our main-method and then make them active again as you implement the methods those lines call. We
in main will call the methods described above pretty much in the order stated, so life might be a bit easier if you implement them in
that same order. Write them as you need them… code a little, test a lot! If message holds a “%.2f” in it, then the method call
String.format(message, someDoubleVariable) can be used to produce a String with a properly formatted dollar amount in it. Do NOT
make your class BankAccount public for this assignment! Just use “class BankAccount etc.”
You must submit a printed and electronic (CD or Floppy) copy of your commented program along with a screen captures of
the output from our main in a manila envelope.
pf3

Partial preview of the text

Download Lab 10: Java Banking Account Program and more Lab Reports Computer Science in PDF only on Docsity!

Name:__________________________________________________________________Section:___________

CIS 120-101 / Overstreet / Fall 2007

Lab 10 – Due: Week 12 (Wed 11/7/07)

Problem Description Design and implement a program with a Java class called “Lab10”. Lab 10 will simulate the activities of a several banking accounts with appropriate operations on each of those accounts. [See Program 5 description where we solved this SAME problem, but had ONLY 1 account because the operations were on class variables. We will now redo this the right way!] Code Requirements: Your code must use the code provided to you on this assignment (you can access the source code for this assignment at the following URL: ). That code will include a main that will create and use objects of type “BankAccount” (you will write the code for this class and will include it within the file Lab10.java (at the bottom). Yes a Java file can have more than one class declaration in it as long as only one of them has a main-method. In this lab the Lab10 class will have a main-method and the class definition that you write for BankAccount will not have a main-method. In essence, Lab10 is acting as a “client” of the BankAccount class. The BankAccount class is thus providing a good abstraction for us! Your output dialogs should have your name on them as opposed to “CIS Faculty” shown in sample output below. All of the class and instance variables in your class definition MUST be declared as “private” (thus access to them from Lab10 will only be via the methods that you write)! Error Checking: The version of main that we supply should be doing this for you. If your code bombs showing any kind of error message, then you have a fix to make. If your program produces output that differs from that shown below it is wrong. Required Instance Methods and Their Semantics : (1) A constructor that takes first name, last name and opening amount [positive or negative] as a starting amount. This method sets all the needed instance variables. The account is considered “open” after this constructor call. (2) A constructor that takes a first name, last name as its only formal parameters (the amount of initial deposit in this case is assumed to be $0). (3) A String method called accountOwner (with no parameters to it) that returns the owners full name with a space between the first and last names. (4) A version of toString that overrides the version in the class called Object. It must, of course, have a signature that looks like: public String toString(); This method should produce a String exactly like the following: “Bill Smith :: (Current Balance = $12.50)“ (5) A void method called deposit that takes a double amount as a parameter. This amount will be added to the dollars in the account (and could of course influence whether it is now overdrawn or not). (6) A void method called withdraw that takes a double amount as a parameter. This amount will be deducted from the dollars in the account (and could of course influence whether it is now overdrawn or not). (7) A double returning method called balance (with no parameters to it) that returns the dollars now in the account. (8) A Boolean method called approveCheckFor with a double parameter to it that specifies some amount. If the account has enough in it to cover a check in that amount then a true is returned, otherwise a false is returned (note that dollars in the account is not modified by this method). (9) A Boolean method called isNowOverdrawn (with no parameters to it) that returns a true if the account is currently overdrawn and a false otherwise. (10) A void method called showAccount (with no parameters to it) that will use a JOptionPane message dialog to display the account owners full name, the account balance, and whether the account is now overdrawn or not. This method is expected to call the accountOwner and isNowOverdrawn methods. The account balance must be shown with two digits after the decimal point. Required Class Method and its Semantics : (1) A method to return the number of accounts that are now in existence. This method, called howManyAccounts, returns an int and takes no arguments. Hints: Comment out parts of our main-method and then make them active again as you implement the methods those lines call. We in main will call the methods described above pretty much in the order stated, so life might be a bit easier if you implement them in that same order. Write them as you need them… code a little, test a lot! If message holds a “%.2f” in it, then the method call String.format(message, someDoubleVariable) can be used to produce a String with a properly formatted dollar amount in it. Do NOT make your class BankAccount public for this assignment! Just use “class BankAccount etc.” You must submit a printed and electronic (CD or Floppy) copy of your commented program along with a screen captures of the output from our main in a manila envelope.

Output 1

Output 2 :

Output 3:

Output 4:

Output 5:

Output 6