Dept. Colloquiua
CS 120
Computer Science I, Fall 2006, Instructor: Jeffrey Horn
COURSE ANNOUNCEMENTS (Tuesday, December 12, 2006)
- What's REALLY New:
- Added some additional example questions and some solutions for the final
exam information (below).
- Final Exam information added. (See bottom of this
page.)
- Not so New (Older Announcements):
- Turrets
- Program II due date changed to end of week (that's Friday, Jimme'!).
Also added a few bits of info. See below.
- Program II (hidden images). See below.
- Homework 5 (Honeycomb). See below.
- Since I missed helping a BUNCH of folks at my Monday office hours, and
since some are still wondering how to do this assignment, I won't take of
any points if you turn in HW4 any time tomorrow, Wednesday, Oct. 18, 2006.
- Homework 4 dropbox is now available on
WebCT. (due date is still midnight Tuesday, Oct. 17.)
- We'll have a bit of lab time in class on Tuesday if you have last minute
questions finishing HW4. Also, Alex our tutor has two hours on Tuesday
in the big lab (NSF 1207), specifically, 1-3pm.
- Don't forget: practice on-line quiz Tuesday in class (Oct.
17). Just practice, so it won't count, but you will need your laptop
to try it! Main goal is to see what it is like to take a WebCT on-line
test, especially one of mine! It will be chance to work out any
"kinks"...
- Homework 4 (graph paper) is now up! See below.
- Program I deadline extended ONE DAY, to Friday, Sept. 22,
2006 (midnight!). Drop box is now working!
- Program I.
- Argonne!
- Quiz on Thursday, Sept. 14.: on-line (maybe; bring
laptop! via WebCT). Topics: (from sections 1.1 and 1.2 of text)
- Order of execution (of commands). Eg., number the
following statements in the order that they will be executed.
- Interpreting graphics programs as in HW1 and HW2.
E.g., which of the following graphics will be drawn by the code in
Figure X?
- New CS Tutor: Alex
Anagnos. He will be available in the lab (NSF 1207) on Tuesdays
from 1-3 p.m. and Thursdays 5-7 p.m.
- HW2 due date is changed from this Friday (Sept. 8, 2006) to Monday, Sept.
11, 2006. Also, you don't have to turn in all the files; just the source
code (.java).
- HW2 is up. See below.
- Welcome to class!
CONTENTS
LECTURE NOTES
HOMEWORKS & PROGRAMS
- Homework 1: "Hi World"
- Handed out: Tuesday, August 29, 2006
- Due: Thursday, August 31, 2006 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: Tuesday, September 5, 2006
- Due: Monday, September 11, 2006 (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)
- 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)
- PROGRAM I: "Making and Publishing Your Masterpiece"
- Handed Out: Thursday, September 14, 2006
- Due: Thursday, September 21, 2006 (submit to WebCT, by 11:55pm)
- Purpose: Learn
- writing "lots" of code!
- (more of) breaking up functionality into small modules (i.e., methods),
- publishing your applet on the web, and
- "nested" method calls.
- Reading: Chapter 2
- Tasks: (total 100 pts.)
- Write an applet, like in HW2, but this time make it draw a complex picture, meaning: (40 points)
- Big (close to full screen) (10 pts.)
- Colorful (multiple colors) (10 pts.)
- Multiple, diverse objects (e.g., a landscape, a floor plan) (10 pts.)
- Complex objects (e.g., a snowman, a house, a tree with many branches, etc.) (10 pts.)
- Use lots of private methods. As a matter of fact, break up your code, so that no method has more than 20 commands! (This is a challenge based on the teachings of my CS 100 professor, Dr. David Gries.) Break up the code into separate logical "chunks" (e.g., "paintHead()", "paintRiver()". (20 points)
- Have at least on private method that calls another private method. That means you have a "nested" method call. For example, if your "paintSnowPerson()" calls your "paintHead()" method). (15 points)
- 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. (10 points.)
- Publish your code on the web via myweb.nmu.edu, or your own web server, if you have one. Do this by making a web page that calls the applet, and putting the web page and the .class file on the server (do NOT publish your source code!) (15 points)
- Turn in via WebCT (compress and submit your entire folder, including your .java file), AND INCLUDE YOUR URL (web address) for your web page.
- Homework 3: "Introduction to Parameters"
- Handed Out: Thursday, September 21, 2006
- Due: Monday, October 1, 2006 (submit to WebCT, by 12am midnight)
- Purpose: Learn
- create and use methods with multiple parameters,
- create re-locatable graphics,
- see and 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: Tuesday, October 10, 2006
- Due: Tuesday, October 17, 2006 (submit to WebCT, by 12am midnight)
- 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 that go from one side of the screen to the other, and vertical lines that go top to bottom. (Assume XGA resolution, which means 1024 by 768 pixels. Remember that (0,0), the origin, is in the upper left corner of the screen, in Java!) (25 points)
- 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!) ( 20 points)
- 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)
- Put your above code into a method that is called from paint and takes the following parameters as input: "(Graphics g, int line_incr, int label_incr)" (20 pts.)
- Draw me a hexagon on your graph paper, either on hardcopy print out or in your program. Make it clear what the coordinates of each vertex is! (either write them down, or just make sure it is easily read off of your labels!) (10 pts.)
- EXTRA CREDIT: 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.) (10 pt.s)
- Here is some sample code from class.
- ALTERNATIVE (CHALLENGE!) assignment: Take "Nate's challenge"! Make a polygon (See the sample code in the text book on pages 1-3, 1-4, that uses the class Polygon. Add a few points to it (at least three!). Now, what if you wanted to make the EXACT SAME POLYGON, only larger, or smaller (and more or less centered on the original polygon)? Assume you have the n points (as int pairs x1, y1, x2, y2, ..., xn, yn). Also assume a "growth factor" g (e.g., g == 2 means grow the polygon to twice the original size). How would you compute the NEW vertices x1', y1', x2', y2', ... , xn', yn' ? Show me code that implements your formula!
Homework 5: "Honeycombs (Hex paper)"
- Handed Out: Tuesday, October 24, 2006
- Due: Tuesday, October 31, 2006 (submit to WebCT, by 12am midnight)
- Purpose: Learn
- Nested loops.
- Floating point numbers (to represent real numbers).
- Tasks: (maximum 100 pts.)
- Take our code we developed in class which graphs a single column of hexagons, one butted up against the other (example).
- Write a method that will "tile" the entire screen with hexagons. You may use nested loops, two methods, or a single loop.
- Comment your code!
- Turn in via WebCT
Program II: "Handling Java Events: Buttons and Mice"
Handed out Thursday, November 2, 2006 Due: Friday, Nov. 17, 2006,end of day Purpose: Learn - the Java event model
- button input
- state variables
Example Code (we developed this in class): Original FollowTheClick (hacked up in class)Simplified FollowTheClickSimple Use of ButtonsTrisha's codeImage codeAudio 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 by displaying a line or arrow that indicates which direction the hidden box is from their click.
- Create a random coordinate (sx,sy). Imagine a "secret" box of width and height 20 at (sx,sy) (5pts).
- Centered 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) (5 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".
- Hints to give the player: (not cumulative! )
- Use clues, like arrows, at fixed location (10 pt.s) Example (applet)
- Use arrows that follow the click (20 pts) Example (applet)
- Use vertical and horizontal lines that define all four limits (30 pt.s) Example (applet)
- Use a box that defines all four sides (40 pt.s): Example (applet)
- 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:
- >= 50pts earns a D
- >= 60pts earns a C
- >= 70pts earns a B
- >= 80 pts earns an A
- >= 90 pts earns an A+
- lose one letter grade for inadequate documentation (i.e., comments; see the file "comment guidelines" (forthcoming...))
- Handing it in:
- Use WebCT. There is a dropbox for Program II. Turn in your souce code (that is, your ".java" file)
- Put it up on the web (5 pts.) and post a link to it on WebCT (5 pt.s) on our CS 120 class discussion page...
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!)
- Take Home Exam
FINAL
COMPREHENSIVE EXAM:
- Tuesday, Dec. 12, 2006, 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 (NOT nested 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