DOC PREVIEW
TRINITY CSCI 1311 - API, Methods, and Conditionals
Pages 9

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 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 9 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 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1API, Methods, and Conditionals3/12/20082Opening Discussion■Do you have any questions about the quiz?■Let's look at some solutions to the interclass problem.3The API■Now that you have a bit more knowledge of what Java code looks like and how classes are organized, let's look at the API.■The libraries for Java are written just like your code. They are broken into classes and those classes have methods.4Static vs. Non-static Methods■We haven't yet written our own static methods. When looking at the API, a lot of the most useful helper methods are static.■Begin static means that they are associated with the class, not any object created from that class.■This is reflected in how we call them. Normal methods are called using the dot notation after the name of an object. Static methods are called using the dot notation after the name of the class.5Problem■There are a few things wrong with our bank account.The formatted string for balance is wrong is we have 0-9 cents.You could call deposit or withdraw with negative values.■What do we need to do to fix these problems?6Conditionals■Fixing the problems on the previous slide requires the ability to only do things in certain situations. That is to say that we need conditional execution.■For example, if the number of cents is less than 10 we need an extra zero in our answer, otherwise we don't.■We also don't want to do the withdraw or deposit if the value passed in isn't positive.■As in Alice we can fix this with a statement that only happens in a certain situation. Like Alice, the main statement for doing this is the if statement.7If Statement■The syntax for the if statement is as follows:if(booleanExpression) {➔statements} else {➔statements}■The boolean expression can be anything that evaluates to a boolean.■The else is optional.■Let's use this to fix the two problems we had with our code.8Customers■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.9Minute Essay■Do you have any questions about the things we have discussed so far this week?■Interclass Problem – Write a simple class for a drivers license that includes an if statement that tells whether a person is old enough to drink. Include a main to test this


View Full Document

TRINITY CSCI 1311 - API, Methods, and Conditionals

Course: Csci 1311-
Pages: 9
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 API, Methods, and Conditionals
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 API, Methods, and Conditionals 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 API, Methods, and Conditionals 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?