DOC PREVIEW
TRINITY CSCI 1311 - Conditionals in Java
Pages 8

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

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

Unformatted text preview:

1Conditionals in Java3/14/20082Opening Discussion■Let's look at solutions to the interclass problem.■What do variable declarations look like in Java?■What is the purpose of conditionals?■What conditional construct did we use in Alice? How did it work?3The if Statement■Just like in Alice, to really get flexibility in our code in Java we need conditional execution.■As with Alice, we can get this through an if statement. The syntax is basically the same.if(booleanExpression) {➔statements} else {➔statements}■The else is optional.■If you only have one statement the {} is optional.■You can string then together by putting another if right after the else.4Problems in our Code■Let's fix the problems that we have in our bank account code that need conditionals.The formatted string for balance is wrong is we have 0-9 cents.You could call deposit or withdraw with negative values.5The switch Statement■For selecting between multiple options Java also has a switch statement.switch(integerExpression) {➔case val1:-break;➔case val2:-break;➔...➔default:}■The argument and cases must be integer types. Note that char counts.■The break just exits the switch. Leaving one out lets control fall through to next case.6The toString Method■When you print an object or concatenate it to a String it calls the toString method of the object.■This can be helpful in many situations.■We can write our own toString method in our classes so that they provide useful information or just a nicely formatted String.public String toString() { ... }7Customers■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.8Minute Essay■What will you do doing for Spring Break?■Interclass Problem – Problem


View Full Document

TRINITY CSCI 1311 - Conditionals in Java

Course: Csci 1311-
Pages: 8
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 Conditionals in Java
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 Conditionals in Java 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 Conditionals in Java 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?