[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Links]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.4.2 API]
[EIJ]
[CS152 2000F]
[CS153 2004S]
Back to Loops. On to Laboratory: Java Basics, Continued.
Held: Monday, 20 September 2004
Summary: Today we check our understanding of Java basics by writing some simple Java programs.
Due
Assignments
Notes:
share CS152
cd CS152
mkdir userid
share userid
cd userid
lab01a.
mkdir lab01a
share lab01a
cd lab01a
kate
a. Create a main class called Critic in package youruserid.lab01a. The Critic class should contain only a main method. That method should prompt the user for his or her favorite color and make a comment on that color.
b. Update Critic so that it makes a different comment for the color blue than for other colors.
a. Create three model classes, Roger, Pauline, and Chris. Each should provide a method, comment(PrintWriter pen, String phrase), that provides a comment on the particular string. (E.g., "Hmmm ... phrase fascinates me.")
b. Create a main class, Panel, with a main method that builds an object in each of the three classes you've just created, prompts the user for a favorite phrase, and asks each of the objects to comment on that phrase.
Prepare a directory structure for a package named lab01.userid.
a. Write a main class, UpCounter, in package lab01.userid. The main method should prompt for an integer and print out the integers between 1 and that integer, inclusive, in increasing order. For example,
Please enter an integer: 5 1 2 3 4 5
b. Write a main class, DownCounter, in the same package. The main method should prompt for an integer and print the integers between that integer and 1, inclusive, in decreasing order. For example,
Please enter an integer: 3 3 2 1
c. Write a main class, UpDownCounter, in the same package. The main method should prompt for an integer, and count from 1 up to that integer and then back down to 1. For example,
Please enter an integer: 4 1 2 3 4 3 2 1
d. Write a main class, EvenCounter, in the same package. The main method should prompt for an integer, and print the positive odd numbers less than that integer. For example,
Please enter an integer: 12 1 3 5 7 9 11
e. Write a main class, DoubleCounter, in the same package. The main method should prompt for an integer, and count up to every number between 1 and the integer entered. For example,
Please enter an integer: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Back to Loops. On to Laboratory: Java Basics, Continued.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Links]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.4.2 API]
[EIJ]
[CS152 2000F]
[CS153 2004S]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed Dec 8 10:37:11 2004.
The source to the document was last modified on Thu Aug 26 20:22:22 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2004F/Outlines/outline.14.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby