90 likes | 219 Views
CS 120 Day 1. Introduction to CS 120 A simple example program. CS 120. Instructor: Thomas Gendreau Office: 211 Wing Office Phone: 785-6813 Office Hours: Monday, Friday 2:30-3:30 Tuesday, Thursday 1:30-2:30 Wednesday 10:15-11:45
E N D
CS 120 Day 1 • Introduction to CS 120 • A simple example program
CS 120 • Instructor: Thomas Gendreau • Office: 211 Wing • Office Phone: 785-6813 • Office Hours: Monday, Friday 2:30-3:30 Tuesday, Thursday 1:30-2:30 Wednesday 10:15-11:45 • email:gendreau@cs.uwlax.edu • Web site: www.cs.uwlax.edu/~gendreau/cs120/cs120.html
CS 120 Grading • 160 points: 10 quizzes (best 10 out of 12) • 80 points: Programming Assignments (best 8 out of 10) • 80 points: 2 Projects • 80 points: Cumulative final exam • 12:15-2:15 Saturday December 17 OR • 12:15-2:15 Wednesday December 21 • 400 total points • A quiz will be given in class every Friday except December 2 and December 9. Friday classes meet Wednesday November 23rd. There will be a quiz on November 23rd. No makeup quizzes will be given. Unusual situations such as multi-week illness will be handled on an individual basis. The exact grade ranges will not be determined until after the final exam. Estimated grades will be shown after quizzes 4, 8 and 12. Border line point values will be assigned letter grades using the instructor's subjective evaluation of a student's work.
CS 120 Readings • Textbook • The Object of Java, 2nd Edition by David Riley • Online Java documentation
CS 120 Goals • Problem solving • Introduction to computer science • Introduction to software engineering • Programming • Java
A Simple Example import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.util.Random; //Controller for the memory game public class MemoryGame implements ActionListener { MemoryGameWindow gameWindow; Random rNum; ColorRectangle items[]; int playBackItem; int toggleCount; Timer timer; int numItems; int nextGuess;
Simple Example (continued) public MemoryGame() { gameWindow = new MemoryGameWindow(10, 10, this); rNum = new Random(); timer = new Timer(1000, this); timer.setCoalesce(false); } private void generateItems() { int i = 0; int next; items = new ColorRectangle[numItems]; while (i < numItems) { next = rNum.nextInt(3); items[i] = gameWindow.getRectangle(next); i = i + 1; } }
Simple Example (continued) public void startGame(int n) { numItems = n; generateItems(); playBackItem = 0; toggleCount = 0; timer.start(); } public void actionPerformed(ActionEvent e) { if (playBackItem == numItems-1 && toggleCount == 1) { timer.stop(); nextGuess = 0; gameWindow.showResponse("YOUR TURN"); } items[playBackItem].toggleColor(); playBackItem = playBackItem + toggleCount; toggleCount = (toggleCount + 1) % 2; }
Simple Example (continued) public void nextMove(ColorRectangle r) { if (items[nextGuess] == r) { nextGuess = nextGuess + 1; if (nextGuess == numItems) { gameWindow.showResponse("YOU WIN"); } } else { gameWindow.showResponse("ERROR IN MOVE "+ (nextGuess +1)); } } public static void main(String args[]) { new MemoryGame(); } }