Dept. Colloquiua
CS 120
Computer Science I, Winter 2007, Instructor: Jeffrey Horn
COURSE ANNOUNCEMENTS (Tuesday April 17, 2007)
- What's REALLY New:
- Homework 6 assigned. See below.
- Not so New (Older Announcements):
- Homework 4 assigned. See below. First part due on Tuesday
- Homework 3 assigned. See below. Due middle of next week.
- Homework 2 assigned. See below. Due end of next week.
- Homework 1 assigned. See below. Due date is now Tuesday, Jan.
23.
- Welcome to class!
- Our first dept. colloquium of the winter semester is THIS THURSDAY (Jan.
18) at 4:00pm in NSF 1209. Click
here for more
details.
CONTENTS
LECTURE NOTES
HOMEWORKS & PROGRAMS
- Homework 1: "Hi World"
- Handed out: Tuesday, January 16, 2007
- Due: Tuesday, January 23, 2007 in class
- Purpose: get acquainted with our programming
environment
- Reading: Beginning of chapter 1 (section 1.1)
- Assignment:
- Follow instructions on the syllabus to download and install BOTH the
TextPad editor and the Java Developers' Kit (JDK) version 2 from the
internet. Note that these are BIG downloads! Do them on a broadband
connection.
- Enter in the code from example 1 (on page 1-1) of our
text, GUI Java. (You can copy and paste it from
here)
- Save it, execute it, debug it, save it again.
- Modify it in your own UNIQUE way! E.g., Draw several
rectangles and print several text fields. Three requirements here:
- Has to be original (no duplicating anyone else's
code in class)
- Has to include multiple SOMETHINGs (e.g., multiple
shapes, multiple text, multiple scroll panes).
- Details on how to turn it: Show it to me
in class!
- Homework 2: "Private Methods"
- Handed Out: Thursday, January 25, 2007
- Due: Friday, February 2, 2007 (submit to WebCT, by 11:55pm)
- Purpose: Learn
- breaking up code into methods,
- system console usage,
- using WebCT dropboxes, and
- commenting your code
- Reading: Rest of chapter 1 (sections 1.2, 1.3)
- Example code, from lecture: Coins
- Tasks: (total 100 pts.)
- Write a class (hint: copy your hw1.java and modify it! Or use an example you copy from lecture or from the book. Put it into a different folder; its own!) (20 pt.s)
- Make at least three private method in your class that draws something unique on the screen. Call the class from your "paint" method. (45 pts (15 pts. for each of the three methods))
- Comment your methods so that it explains WHAT the method does without telling all the details of HOW. Also comment your class, at the top of the file, with your name, homework number, date, and the name of this class. (15 points.)
- Print out a message to the console window, from each private method, that states the name of the method has just been called with. (20 points)
- Turn in via WebCT (just your .java source code file)
- Homework 3: "Introduction to Parameters"
- Handed Out: Tuesday, February 6, 2007
- Due: Wednesday, February 14, 2007 (submit to WebCT, by 12am midnight)
- Purpose: Learn
- create and use methods with multiple parameters,
- create re-locatable graphics,
- use loops.
- Reading: First part of Chapter 2 (sections 2.1 and 2.2)
- Tasks: (maximum 100 pts.)
- Write a method M that draws a complex graphics object. (By "complex", I mean a collection of multiple, diverse, related shapes that make up a coherent whole. For example, the hat on the cat-in-the-hat, or the mascot from your favorite team, or a company logo. It can be "boring", and abstract, but not just a random collection of ovals and boxes! Don't try to make it too realistic, too complex. or too "3D". Remember that you have to "parameterize" your drawing code in step 2 below!) (25 points)
- "Parameterize" the location of the graphics in terms of its (x,y) location on the screen, so that method M can be called with different values of x,y and the graphic will be drawn at or near the given x,y coordinate. (25 points)
- Demonstrate that your method M is properly parameterized by calling it with different values of x and y. (25 points)
- Use a loop with randomized values to make hundreds or thousands of your graphics object in different locations. (25 points):

- Turn in via WebCT (just your .java source code file)
- Homework 4: "Graph Paper"
- Handed Out: Thursday, Feb. 15, 2007
- Due: (in four parts; see tasks below)
- Purpose: Learn
- loops, in particular "for" loops,
- sequential loops,
- the use of "if-then" and "if-then-else" constructs, and
- the modulus operator ("%").
- Reading:
- Tasks: (maximum 100 pts.)
- Write code that displays graph paper as we discussed in lecture (example).
- It should have a series of evenly spaced horizontal lines (every 10 pixels) that go from one side of the screen to the other,
- and vertical lines (every 10 pixels) that go top to bottom.
- (25 points) DUE Tuesday, Feb. 20, 2006
- Generalize your code The lines should be spaced out according to an int variable (e.g., call it "incr"), with 0 < incr. So for example if incr == 5, then a line will be drawn every 5 pixels down the page (and across too; use incr for both horizontal and vertical spacing; this means you will always have squares, not rectangles!) ( 25 points) DUE Thursday, Feb. 22, 2006
- Label some of the lines along the top and along the left sides of the screen, as in the example. Have the resolution (spacing) of the labels be controlled by another int variable. This might be called "label_incr" for example, but that is up to you. Note that the label increment and the line increment should be SEPARATE variables! This way, your program can have separate spacing for lines and for labels, as in the example. ( 25 points) DUE Tuesday, Feb. 27, 2006
- Draw thicker lines every few lines. Use a separate variable that controls the resolution of the thick lines. For example, click here. (Hint: use "fillRect" to make a thick line.) (25 pt.s) DUE Thursday, March 1, 2006
- Here is some sample code from class.
- Homework 5: "Handling Java Events: Buttons and Mice"
- Handed out Tuesday, March 20, 2007
- Due: PART I due Tuesday, March 27, 2007, PART II, the rest, due on Wednesday, April 3, 2007
- Purpose: Learn
- the Java event model
- button input
- state variables
- Example Code:
- Original FollowTheClick (hacked up in class)
- Simplified FollowTheClick
- Simple Use of Buttons
- Trisha's code
- Image code
- Audio code
- Assignment:
- Copy this "template code" to a new folder
- Make a graphical guessing game with the following functionality
- The game is to make the user guess where the hidden box is by clicking on the screen.
- We will give the user hints each time he/she clicks and misses.
- Create a random coordinate (sx,sy). Imagine a "secret" box of width and height 20 at (sx,sy) (10pts).
- Center the hidden (secret) box at (sx,sy) by drawing it from (sx-10,sy-10) to (sx+10,sy+10). (See "centering graphics" in section 2.5 on page 2-14) (10 pt.s)
- Listen for a mousepressed mouse event.
- If your player clicks within the magic box centered at (x,y), then display the box (make it visible). (see section 2.3, "Expressions" on page 2-11 and also section 3.4 on page 3-8 for boolean expressions) (10 pts.)
- If your player misses with the click, then update the "hints".
- Some hints to give the player: (cumulative! )
- Use color to indicate how close the click was. (Let's say redness indicates proximity to secret box: the brighter the red, the closer the click was!) (20 pt.s) (see example from class)
- Use clues, like arrows, at fixed location (20 pt.s) Example (applet)
- Use arrows that follow the click (20 pt.s) Example (applet)
- Use vertical and horizontal lines that define all four limits (20 pt.s) Example (applet)
- Use a box that defines all four sides (20 pt.s): Example (applet)
- After a certain number of clicks, have a "helper" pop up that points the way, or maybe pops up near sx,sy. (20 pt.s)
- Any other, decent, interesting clues that you can come up with... (20 pt.s)
- Maintain and print (on the graphics screen!) the number of clicks so far. (10 pts.)
- Use an external file (like gif, jpg, or bmp) for your hidden box (10 pts) Get your own!
- Play some music (or other sound) when the player clicks (maybe upon winning, or upon missing, or both) (10 pts) Get your own!
- Grading:
- max 100 pts.
- lose up to 20 POINTS for inadequate documentation (i.e., comments; see the file "comment guidelines" (forthcoming...))
- Handing it in:
- Use WebCT. There will be a dropbox for HW5. Turn in your souce code (that is, your ".java" file)
- Put it up on the web and post a link to it on WebCT on our CS 120 class discussion page... (10 pts.)
Homework 6: "Let's Make A Deal!" - Handed out Tuesday, April 17, 2007
- Due: Thursday, April 25, 2007 BEFORE CLASS!!!
- Purpose: Learn
- extensive use of state variables
- extensive use of buttons
- use of a controller class to coordinate other classes
- the difference between a class and an object!
- Assignment:
- Implement an interactive version of "Let's Make a Deal", as discussed in class and in the video.
- The user of your program should be able to play the game over and over again, to see if the "switch" strategy really is better.
- The game should have three images for the closed doors, plus an image for the grand prize and an image for the booby prize. (You may use the images I used in the video.)
- Here is sample code from class.
- The game should work as follows:
- SETUP: A random number (1,2, or 3) is chosen. The prize is placed behind the corresponding door. The other two doors get the booby prizes (e.g., donkeys).
- The player initially sees three doors, all closed. Instructions should appear (or be spoken!) telling her to choose a door (by clicking on it, for example).
- Once a choice is made, it should be visible (e.g., a circle or box around the chosen door, or the door might "glow"). The player should be able to change her mind and choose another door by clicking on it. The player can do this as many times as she likes until she is ready to push the "Monty button" (see next step). Only one door can be selected at a time.
- Then the player is shown a button of some kind, to press in order for Monty to reveal what is behind another door. This button becomes active and visible ONLY after the player has selected a door.
- When the Monty button is pressed, a door is opened that is NOT the one chosen by the player and is NOT the one with the prize behind it! (If there are TWO such doors, you must choose one at random.)
- The player is now told to choose (to stay with her original choice or to choose the remaining door). When ready, she clicks the Monty button again.
- Now all the doors are opened, and the "score" (number_of_wins/number_of_games) is updated. The current score should be always displayed.
- A "new_game" button resets the game but not the score.
- A "reset" button resets BOTH the game AND the score.
- GRADING: (tentative)
- "A" if I can play the game and verify that "switch" is twice as good a strategy as "stay"
- "B" if I can play the game multiple times.
- "C" if I can play the game at least once.
- "D" if I can get a door open.
Grading:
- max 100 pts.
- lose up to 20 POINTS for inadequate documentation (i.e., comments; see the file "comment guidelines" (forthcoming...))
Handing it in:
- Use WebCT. There will be a dropbox for HW6. Turn in your souce code (that is, your ".java" file)
- Put it up on the web and post a link to it on WebCT on our CS 120 class discussion page... (10 pts.)
PROGRAMMING Language: Java
Free
Downloads: Click
here
for instructions on how to download TextPad and Sun's Java 2
Platform.
Here is EventPanel, you'll need it for some of the examples in the
book. Also, you will need PanelApplet.java.
Helpful Links:
Platform: NMU IBM ThinkPads OR Apple iBooks
TESTS AND QUIZZES
- All tests are open book and open notes. Some require your
notebook computer (I'll let you know ahead of time!) NONE are
"open neighbor"! (i.e., no help from others!)
FINAL
COMPREHENSIVE EXAM:
- Tuesday, May 1, 7pm NSF 1209 (usual time, usual classroom)
- Open book, open notes
- Topics:
- Basic Java:
- basic data types: int, boolean, String,char
- variables: declaring, initializing, changing, printing (e.g., "declare an int variable x, initialize it to 435, double it, and print it to the CONSOLE"; solution: int x; x = 435; x = x + x; System.out.println("x is " + x); )
- Assignment statements. (know that "x= 43;" is correct, but "43 = x;" is not!)
- Sequential execution of statements.
- Boolean expressions (sample questions) (Solution to sample questions)
- If-then-else
- Loops Example Question, and SOLUTION (this one is a COMPUTER question! meaning it is easiest to answer by programming...)
- Methods
- What is in a method signature? (access type (public or private), return type (void or some data type), method name, parameter list)
- Example questions.
- Classes
- A class is a collection of related methods and data (state variables).
- State variables