DOC PREVIEW
Duke CPS 004 - Chap 6 – Problem Solving

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Chap 6 – Problem Solving Mar 29, 2005Prof. Susan RodgerAnnouncements• Read Chapter 7.1 for next time• Assignment 7 is extended, due Tuesday April 5!What we will do today• Problem Solving – Chapter 6• Practice writing methods and functions• Talk about assignment 7Problem To Solve• Given three animals standing in a row• Resize each of them randomly by 1(no change) to 4 times its size• Whichever is taller, spin around once to the right, once to the left• Sort the animals by their height• Display message “In order”whenever in order by increasing heightObjects in the world• Animals – chicken, rabbit, and penquin• Balls (will be invisible always)– tennisball1 – represent position 1– tennisball2 – represent position 2– tennisball3 – represent position 3• 3D text – “In order! – Invisible until animals in order by heightRandom Integers• Bug in Alice with “integers only” and how they are used…..• Return ?world. my first methodmakeTallerAnimalSpinAround• Need to know which of the three animals is tallermakeTallerAnimalSpinAround• Use isTaller3Another way – whichIsTaller3?How do we use whichIsTaller3?• How do we turn the taller of the three around once to the left?How do we check if items are sorted by increasing height?• Check if object in position 1 is shorter than object in position 2 which is shorter than object in position 3• How do we know which animal is in a position?isSortedByIncreasingHeight whichObjectIsClosestToCheckIfSortedByHeight• Use isSortedByIncreasingHeight• Use whichObjectIsClosestToSortAnimalsByHeight• How? Lots of answersOne way – moveAnimalsToSortedPositionIfAnimal1IsTallest• 3 parameters – anim1, anim2, anim3• If anim1 is the tallest, then compare other 2 and move each to corresponding tennisball• If anim1 is not the tallest, don’t do anythingmoveAnimalsToSortedPositionSortAnimalsByHeightProblem is Solved!•DemoAssignment 7 - Gatekeeper•Demo• Useful things to do– When S is typed – show answer– Display tennis balls til program is working– Randomly set gatekeeper – game different each time playedAssignment 7 – Gatekeeper Useful functions• World.SwapPlayers (obj player)– Swap player with player furthest away• World.whichObjectNearBall (obj ball)– Return object closest to ball• World.NearWhichBall (obj player)– Returns ball that player is closest to• World.whichObjectIsGateKeeper– Returns object that is gatekeeperAssignment 7 – Binary Code Game•Demo• Useful info– When S is typed show answer– Randomly set answer– How do you tell if lever is up or down?• Use invisible sphere – two colors • Don’t compare sphere’s position with lever – bug in Alice so this doesn’t workAssignment 7 – BCG Useful Functions• changeSphereColor (obj sphere)– changes color of sphere to other color• switchFlip (obj switch)– Change lever position (and sphere color)– Check if valid code and if so, indicate• isValidCode– Return true if code is valid• isSwitchUp (obj switch)– Returns true is lever is up• whichSphereIsClosest (obj switch)– Returns sphere that is closes to


View Full Document

Duke CPS 004 - Chap 6 – Problem Solving

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chap 6 – Problem Solving
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chap 6 – Problem Solving and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chap 6 – Problem Solving 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?