TRINITY CSCI 1311 - API, Methods, and Conditionals (9 pages)

Previewing pages 1, 2, 3 of 9 page document View the full content.
View Full Document

API, Methods, and Conditionals



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

API, Methods, and Conditionals

77 views

Lecture Notes


Pages:
9
School:
Trinity University
Course:
Csci 1311 -
Documents

Unformatted text preview:

API Methods and Conditionals 3 12 2008 1 Opening Discussion Do you have any questions about the quiz Let s look at some solutions to the interclass problem 2 The 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 3 Static 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 4 Problem 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 5 Conditionals 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 6 If Statement The syntax for the if statement is as follows if booleanExpression else statements 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 7 Customers 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



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

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 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?