CompSci 4Chap 9 Sec 1 and 2 Apr 14, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements• Read Chapter 10.1 for next time• Sign up for Exam time during finals week– Monday 2-5pm, LSRC D106– Wednesday 2-5pm, LSRC D106– Saturday 2-5pm, LSRC D106 (scheduled time)• Reading Quizzes - 125 points perfect score,– There are 149pts +, + 5 survey ptsWhat we will do today• Lecture on Chap 9– Lists and List Search• ClassworkCollections• In some animations, several objects must perform the same actions– Example: marching band marching• It is convenient to collect all objects into a group (collection)– Major benefit – write code for all the objects in the group (rather than separate code for each object)List• A list - one way to organize objects into a collection– You may use lists to organize• Shopping list• Todo list• In programming, a list is a collection of objects or information. We call an organizing structure a data structure.Creating Lists• In Alice, a list can be a list of numbers, or a list of objects, or a list of colors, etc.• Let’s create a list of chickensCreate List (cont)• Type in name• Select type• Select “make a list”• Add chickens to list (click “new item” 4 times)•Result is:Programming with a List• Can “iterate through a list”– Do something to each item in the list• In order (use “For all in order”)• All together (use “For all together”)Example/Demo: Iteration in OrderFor each chicken in orderchicken says “hello”For each chicken in orderchicken turns its head and neck aroundApplying a Part of an object• Drag in chicken turn• Select part• Drag over part• Drag in item• Type in partExample/Demo: Iteration TogetherFor all chicken togetherchicken says “hello”For all chicken in togetherchicken turns its head and neck aroundList Questions• What are differences between For all in order and For all together?• When would you want to use each of them?• What can you put in a list?• When can you refer to a part of an object in a list?List Search Example• WacAMole game• Moles pop up from holes, user tries to whack (click) them• Game over when 10 moles whacked.Score – uses “For all in order”Classwork today• Create a list of players • Make them do several
View Full Document