Computer Science I - 810:061:01 and 810:061:02 - Fall 2002 - 2nd four
weeks
ObjectDraw
blue sheet quick reference.
HELP:
Color coded TA Schedule for Daniel and PJ, indicating
the
WRT 339 lab TA hours in
BLUE
and the WRT 112 TA hours in RED.
- Monday, September 23rd Defining Your
Own Classes, such at T-Shirts (see Williams College book, chapter
4) and coin purses (See page 90-92 of Big Java).
- Wednesday, September 25th Local
variables, PIVs (Private Instance Variables) and Parameters are the
big three categories of data you will see inside of any class definition.
- Here is the Coin Purse
example
from Wednesday's class 9/25/02.
- Here is the Coin Purse
Version 2 to preview befor Friday's class on 9/27/02. This is
the last Friday class in September, by the way. Where will your
understanding of Java and programming and problem solving and
skill at developing algorithms be by the end of the last full
week of October classes?
Play with this Coin Purse
program BEFORE Friday, September 27th, 2002.
How do I use the Project menu, Compiler Settings for Project...
command? If you don't want to save a Project that uses
objectdraw.jar under a NEW NAME, using Project menu, Save As...
to ensure all the settings are correct.
- Command
you use when in jGrasp.
- See dialog box for
Flags/Args/Main and the
need to set the following (for Java, NOT for Ada!):
For ALL programs that use the William's College
--- textbook objectdraw package.
-classpath objectdraw.jar
For my Java program that uses the Purse class, you just add
that to the -classpath so the compiler looks for it.
-classpath objectdraw.jar Purse.java
Note that the Purse.java file should be in the same folder or
subdirectory as you have the client .java that imports
the class and uses its capabilities by constructing
Purses or Tshirts or whatever objects of the class!
- See dialog box for
HTML settings
for the Applet Window that the Project should have.
archive="objectdraw.jar"
is all you have to add to the
default HTML, which you can Copy
to the windows clipboard with
control+C and then Paste back
with control+V.
APPLET
archive="objectdraw.jar" <---- Only phrase you add.
code = %MAIN_CLASS.class
width = 400
height = 400>
/APPLET
Note: 2 Greater Than and 1 Less Than symbols removed so you
can see the HTML, instead of the browser's
interpreting of the HTML! See the GIF file snapshot...
- See a very instructive sample output
that
illustrates why pennies
and storing your money at int (or long) inside the class is SO MUCH
BETTER
than storing it as double (or float).
For example: $7.89 should be stored as the int 789 for
the number of cents or pennies it represents, rather than the
7.89 floating point or REAL number representation the computer
provides.
CoinPurseFlagsArgs.gif CoinPurseSettingsHTML.gif
CoinPurseProjectMenuCompilerSettingsCommand.gif CoinPurseStorePennies.gif
Assignment #4: Lab
4: Yahtzee game - dice and writing
the Die class.
How to do WHILE LOOPS and
REPETITION
in Java using the while statement.
While loops exercise and examples.
Monday, 09/30 class exercise. Do the exercise on your own AGAIN
before the Wednesday class. Can you think of several different ways
to solve it?
Answer to Die class getRoll() method
questions. The PIV currentRoll is an intEGER variable that remembers what
the value of the die is, for each of the objects in Yahtzee game.
die1, die2, die3, die4 and die5 each have their own PIVs.
Clarification on the canvas and the
this Java keyword used to refer to the methods or the PIVs of
the current object.
this.canvas = canvas;
You do NOT need to use the this.canvas = canvas idea, unless
you wanted to have your roll() method create a new RED LINE
for every roll that the user did. Then it would need to know
where, from the PIV canvas!
There are 14 RED lines drawn on the Yahtzee game
shown below, representing the 14 times that the user clicked the
Reroll button.
// From the Die class, with the lines to implement the roll
// removed, but with the two statements that draw a RED LINE
// and prepare for the position of the next RED LINE shown.
// Note how this would NOT work, except for the PIV canvas!
// ------
public void roll()
{
// ------
new Line(150, lineY, 250, lineY, canvas).setColor( Color.red );
// ------
lineY++;
}
Friday, October 4th Lecture
notes and BoxBall Lab 5
assignment. CHAPTER 5:
Read and study carefully
chapter 5 of the Williams College textbook as you
study these lecture notes.
Lab #5
assignment to play the simple game of
dropping a ball into a box from a certain height. Note that you must
do a DESIGN OF YOUR CLASSES FIRST!
Boxball assignment:
THERE ARE
HANDOUTS FOR LAB #5 TAPED TO MY OFFICE DOOR,
Wright 106. (The 9 a.m. class did not get the handout).
Download the lab_5.gpj that
has RELATIVE file references. You would need to fix the other
lab_5.gpj project file, as it was accidently saved with absolute
file references to Box.java, Ball.java, Boxball.java and objectdraw.jar
files.
See the Boxball game
phase #1 demonstration,
with
helpful hints and directions for getting more than halfway through
the project.
See the
completed
Boxball game, with a few extra features added.
Class #18 review: Summary of and examples from the Monday, October 7th class and
lecture.
Boxball game Helpful Hints
email #1 of 2.
Boxball game Helpful Hints
email #2 of 2. Also EXAM ONE being Wednesday, October 16th.
Class #19 preview:
Raindrops
keep filling up the collector and falling on my head.
Example helpful for understanding the public
onBallHittingBottom()
method techniques and issues for your Boxball class,
and how the Ball class could call it. Hopefully,
this will be clear after you study THIS
example. Look at this ahead of time.
Review of class #18 and chapter 5 is useful too, as this is
a development of the DropCollector and the FallingBall classes
from pages 156-157 of the book.
Here is
an example that uses a dialog
box to gather input from
the user, then uses standard String processing and while loop
techniques to print your favorite movie in a triangular pattern,
using the Courier New font.
See a Boxball game that does not produce correct output.
"Hey, I Made that Shot!"
Boxball game, with some added features like randomly sized
ball objects, and the 10 second pause() before doing the hide()
method action.
Boxball game: Lab 5 at 5 p.m. is
okay. Lab 5 by 9 a.m. or 10 a.m. isn't required.
Also important information about midterm EXAM.
EXAM WEDNESDAY: while loop and Color and FilledRect practice question
and exercise.
To be solved in Monday
exam review, but try to solve it yourself FIRST, at least the simpler
version. Can you solve this without looking at the book or lecture notes
or blue sheet? Try to simulate the closed book test conditions and test
your memory and understanding of the while loop pattern.
Midterm exam outline of topics and practice
questions is still in progress.
Solution to while loop RED rectangles problem:
while loop exercise
has 5 staggered red rectangles.