[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Back to Object-Oriented Programming. On to Loops.
Held Monday, April 26
Summary
Contents
Notes
Result in the add
predicate take? It should be a number using the pred/succ
notation.
pred and succ defined?
They're not; they're just placeholders.
DayOfWeek type
as:
public class DayOfWeek { };
public class Monday extends DayOfWeek { };
public class Tuesday extends DayOfWeek { };
public class Wednesday extends DayOfWeek { };
public class Thursday extends DayOfWeek { };
public class Friday extends DayOfWeek { };
public class Saturday extends DayOfWeek { };
public class Sunday extends DayOfWeek { };
DayOfWeek today = new Monday();
weekend
predicate
public boolean weekend(DayOfWeek day) {
return (day instanceOf Saturday) ||
(day instanceOf Sunday);
}
public class DayOfWeek {
// Numeric equivalents to the days. Should only be used in
// the constructor.
public static int SUNDAY = 0;
public static int MONDAY = 1;
public static int TUESDAY = 2;
public static int WEDNESDAY = 3;
public static int THURSDAY = 4;
public static int FRIDAY = 5;
public static int SATURDAY = 6;
// The day for the current day of the week.
protected int day;
// Build a new day of the week.
public DayOfWeek(int day) { this.day = day; }
// Compare two days of the week
public equals(DayOfWeek other) {
return this.day == other.day;
}
// Advance to the next day.
this.day = (this.day + 1) % 7;
} // class DayOfWeek
if (x < 2) y = 2; else y = x;
History
Back to Object-Oriented Programming. On to Loops.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
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/CS302/99S/Outlines/outline.34.html
Source text last modified Wed Apr 28 12:12:54 1999.
This page generated on Wed Apr 28 12:23:44 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu