1 / 9

CS 120 Day 1

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

treva
Download Presentation

CS 120 Day 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 120 Day 1 • Introduction to CS 120 • A simple example program

  2. 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

  3. 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.

  4. CS 120 Readings • Textbook • The Object of Java, 2nd Edition by David Riley • Online Java documentation

  5. CS 120 Goals • Problem solving • Introduction to computer science • Introduction to software engineering • Programming • Java

  6. 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;

  7. 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; } }

  8. 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; }

  9. 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(); } }

More Related