[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Back to Even More Classes and Objects. On to Loops.
Held Tuesday, February 2
Summary
if statement
switch statement
Contents
Notes
Code
at the top of every online lab.
int and its
ilk)
String)
Point)
x < y (less than)
x <= y (less than or equal to)
x == y (equal to; note there are two
equals signs)
x != y (not equal to)
x >= y (greater than or equal to)
x > y (greater than)
equals
method. (It does need to be defined in most cases.)
/**
* Determine if the current point is within one unit of the origin.
*/
public boolean nearOrigin() {
return (this.distanceFromOrigin() < 1.0);
} // nearOrigin()
b1 && b2 (and)
b1 || b2 (or)
!b (not)
/**
* Determine if the current point is bothersome. That is, it is
* within half a unit from either axis.
*/
public boolean bothersome() {
return (Math.abs(this.xcoordinate) < 0.5) ||
(Math.abs(this.ycoordinate) < 0.5);
} // bothersome()
if or conditional statement is one of the
simplest control structures.
if statement.
if (test) {
statements;
} // if
if (test) {
statements;
} // if
else {
statements;
} // not test
if
statements. (Some other languages do.)
if statements, such a solution is neither readable nor
efficient.
switch statement
(like the case statement in Pascal).
switch (integer-valued-expression) {
case value1:
stuff-to-do;
break;
case value2:
stuff-to-do;
break;
...
default:
stuff-to-do;
break;
}
break, execution will continue into
the next case.
byte, short, int,
long, or char valued expressions.
break has other uses, which you'll see later.
What are some other ways we might use conditionals with the
Point class?
What are some other ways in which you might expect to use conditionals?
History
Back to Even More Classes and Objects. On to Loops.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99S/Outlines/outline.06.html
Source text last modified Fri Mar 12 13:06:53 1999.
This page generated on Fri Mar 12 13:12:41 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu