DOC PREVIEW
TRINITY CSCI 1311 - Libraries and Instance Methods
Pages 7

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Libraries and Instance Methods3/10/20082Opening Discussion■Let's look at some solutions to the interclass problem.3Testing and Unit Tests■In order to be certain that a program actually works, we have to test it.■A unit test is a test written to check the functionality of one particular class. We typically create them by making another class that uses the first one and does things we can verify the answers to.■The assert directive is a way of checking whether the answer to something came out the way we expected it.■There are also tools like JUnit that can help with building and running unit tests.4Problem■I'd like each and every bank account we create to have a new account number. This way no two accounts have the same number.■I'd also like to have a method that will validate if a particular account number if allowed.■How can we do this? What is the challenge we run into?5Instance vs. Static Methods/Data■The solution to our problem lies in the use of static. We need something that is associated with all bank accounts, not just one.■To accomplish our task, let's put a static int into the BankAccount class. This will store the number of the next bank account.■Every time we make a BankAccount (remember that calls a constructor) we change that number in predictable way.■The balance is non-static. Every BankAccount gets its own. On the other hand, nextAccountNumber is static. All BankAccounts share it.6Money and Customers■Let's finish what we started last time and make methods that give us strings that nicely format the value of the balance.■I'm also unhappy with our way of keeping track of who the account belongs to. If one person has more than one account with our bank we run into some odd situations.7Minute Essay■Imagine a class called Student. What properties and methods might you put in that class?■Interclass Problem – Do problem


View Full Document

TRINITY CSCI 1311 - Libraries and Instance Methods

Course: Csci 1311-
Pages: 7
Documents in this Course
Arrays

Arrays

12 pages

Arrays

Arrays

10 pages

Applets

Applets

5 pages

Arrays

Arrays

8 pages

Methods

Methods

12 pages

Drawing

Drawing

8 pages

Load more
Download Libraries and Instance Methods
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Libraries and Instance Methods and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Libraries and Instance Methods 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?