1 / 31

Lecture 11

Lecture 11. Alice Project Deliverable 1: Extension to Midnight! Midterm next class Midterm review 4-6pm WED Pepper Canyon Hall 106 R ed scantron (1/2 page) at bookstore (get 2) and pencil Closed book, no cheat sheet Sample midterm: PeerWise and posted “explain”

Download Presentation

Lecture 11

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. Lecture 11 • Alice Project Deliverable 1: Extension to Midnight! • Midterm next class • Midterm review 4-6pm WED Pepper Canyon Hall 106 • Red scantron (1/2 page) at bookstore (get 2) and pencil • Closed book, no cheat sheet • Sample midterm: PeerWise and posted “explain” • DOES NOT COVER Chapter 7 • Seated by random seat number as you walk in the door • Get assignment in lobby • If you have an AFA for midterm, please use course communication form: put “AFA MIDTERM” in comment area

  2. Deliverable 2:Due beginning of Lab next week! • Fix up storyboards (expand, change, etc. as needed) • Implementation Strategy Diagram (what methods call what other methods?) • Background Scenes created with objects in them • Methods "created" with comments inside about what goes on there • The actual code you can fill in during lab

  3. You will need a red half-page scantron -- bookstore How To Study For Exams in CSE3(also redo homeworks and labs (or at least review) ) • Re-Take Clicker questions (not just “review” them) • Use PeerWise, read and re-phrase for yourself an explanation • Practice writing down your explanation, use the sample midterm as a guide • Midterm Review with Sarah • Wed, 4-5:50pm • Pepper Canyon Hall, 106 • Bring specific questions you want her to review… • E.g., their name on PeerWise…

  4. What is the BEST description of how many times a while loop executes? • Some fixed number of times that the programmer can determine before the code runs • Some fixed number of times that can be calculated with a function • Some variable number of times that is determined by the distance of one object to another • Some variable number of times that programmer cannot determine before the code runs

  5. What loop header would keep a shark swimming after a goldfish until he was within 0.5 meters behind the goldfish?

  6. We change the while loop Boolean expression controlling the chase to thisWhat does it do (when will the loop iterate)? • Chase until the goldfish turns blue • Chase until the goldfish turns a color other than blue • Chase until the shark gets close

  7. Bunny Square Dance • We want to direct the bunny to hop in a square pattern. The “length” of each side of his square should be 5 hops. • Here’s the structure of our code, what numbers would you put in for each missing number?

  8. Goal: Hop in a square, 5 hops on each side

  9. What does this code do? • Makes the guy move “up close” to the girl • Makes the guy move toward the girl, but not all the way toward her • Makes the guy move toward the girl and then go on past her • I don’t know

  10. The primary benefit of using a function to control the number of times a loop runs is… • The function can be used to make the loop run a fixed number of times • The state of the world can be used to calculate how many times a loop should run • The function can be used to allow the loop to run forever. • I don’t know STOP, ASK PARAPHRASEEXAMPLE

  11. Games: Infinite loops and events • Set up: • A bunny, a cat, and a hawk all “move” in “squares” 2.5 meters on a side • moving forward .5 meters at a time • An anvil hovers above their head • Game: • When I click on an animal, the anvil drops down and “smooshes” them (they go invisible) then the anvil returns to it’s place so I can click again • An infinite loop is used to keep all the animals continuing to move in their square patterns • The question I will ask you is about the nested loops controlling this game (how many times does each run)

  12. In the nested loops that control this code how many times should the loops run?

  13. After I click on an object (say the bunny) and call goBye that object stops moving around • True • False • I don’t know

  14. Section 7.2 While (Indeterminate) Loops • While loops execute some number of times that we cannot determine before the code runs • “Programming allows a person to think more logically, thinking in order and debugging allows the user to gain valuable problem solving skills. • Aspiring to go to law school, thinking logically is extremely important and I think this has helped.”

  15. If I have a chase that should keep going on until the goldfish turns blue(pretend he turns blue after fleeing for a certain amount of time)what condition should we use to control the while loop in the chase method? D) A and C E) B and C

  16. Hint to getting while loops right • Humans naturally think “until” • I’ll keep spending until I run out of money (balance <= 0) • I’ll keep dancing until I fall asleep • Computers use “while” loops – the opposite • I’ll keep spending while I still have money (balance > 0) • I’ll keep dancing while I am not asleep • While I have a dirty dish, I’ll keep washing dishes

  17. Let’s have a race… • A • Wind up penguin (he just goes) • While loop with “walk and spin” inside it • Jet-pack penguin2 (controlled by <- event) • Moves forward .5 meters • Race to a stop sign (within 2 meters) • Whenever someone gets within 2 meters • Stop looping (going)

  18. When should we keep going?e.g. while loop expression true(P1: wind up, P2: jet pack)

  19. Which while loop header (tile) would you use to control the “going”?

  20. What does the other one do? This would STOP the game (evaluate to false) when • Both penguins must be close to the stop sign • Either penguin is close to the stop sign • Neither penguin is close to the stop sign • I don’t know

  21. Truth Table for OR logical operator

  22. Truth Table for AND logical operator

  23. Let’s look at the code I wrote:

  24. The jet pack penguin (P2) can move forward on a <- event when • Neither penguin is close to the stop sign • The windup penguin is close, but the jet pack penguin isn’t • The jet pack penguin is close, but the windup penguin isn’t • Any time (any possible situation of TT, TF, FT, FF)

  25. Both penguins stop moving when someone “close”To fix this we’d need to create how many of the following? • Method for <- event handler • Method to be called by the windUpAndGo method • If statement in <- event handler • If statement in penguin move method • If statement in windUpAndGo method

  26. Which if statement would you want and why?Allow to move when… C) Both A and B D) Neither A nor B E) I don’t know

  27. Let’s Build This…

  28. 2 meters from the stop sign? That seems far!(3-D object representation trickiness) • Stop Sign center: in middle SIGN • Penguin center: in middle of FEET • I want to control stopping by distance of penguin center from BASE of stop sign! • Use math – again SQRT( c*c – b*b) SQRT (penguin.distanceTo(stopSign) *penguin.distanceTo(stopSign) – stopSign.height * stopSign.height)

More Related