DOC PREVIEW
TRINITY CSCI 1311 - Lists and Arrays
Pages 11

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 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 11 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 11 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 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Lists and Arrays2/11/20082Opening Discussion■Let's look at solutions to the interclass problem.■Minute Essays3Problem■I want to be able to do our tag game with more objects and I don't want to have to repeat writing the same code over and over again.■I could also want the mummy to go and attack many other objects in order of proximity and not have to repeat a lot of code.4Working with Multiple Objects■While we have given ourselves a lot of power in Alice, there are still some things that are difficult. Working with a large number of different objects is an example.■To do this we need some construct in the language that represents a group of things so that we can manipulate the group or give commands to elements in the group.■In Alice we accomplish this with lists and arrays.5Lists in Alice■A list is a type of abstract data type with certain operations defined on it that mimic what we generally think of as things we can do to a list.■You use a list in Alice when you have a collection of objects that you want to add to and remove from.■The dialog box that comes up for variables, parameters, properties, and function return types has an option that allows you to make it into a list. Lists can hold any of the Alice types in them.6List Operations■Alice provides the operations forAllInOrder and forAllTogether to allow you to do something to all of the elements of a list.■The loop will create a variable that stores each item from the list and executes the code in the loop body.■At this point we need to make a list and demonstrate using each of these constructs on the items of the list.7List Methods■Lists have methods in them that we can call to modify the contents of the list.Three versions of add put new items in the list as different locations.Versions of remove take something out of the list.The clear method takes everything out of the list.■Note that the index of a list starts at 0, not 1. This is common in many modern programming languages. So the add method with a first argument of 0 places a new item at the beginning of the list.8List Functions■Lists also have functions that we can call to get information from the list.size tells us how many elements are on the list.firstIndexOf searches for something in the list and gives the index it first appears at.lastIndexOf is similar to firstIndexOf, but starts searching at the end.[] get an item from the list.getLastItem and getRandomItems return the respective items.9Arrays■Arrays are much like lists and in most languages are the most commonly used way of dealing with many things.■Unlike lists, the size of an array doesn't change after it is created. It has a fixed number of slots. You can set elements, but you can't insert and you don't really have the option to remove.■Unfortunately, arrays don't work well in the current version of Alice so we will pretty much ignore them and use lists.10Coding■Let's actually do something with a list in our program.11Minute Essay■How might you use a list in your project?■Remember to turn in your project ideas.■Interclass Problem - Place four objects in a world. Three should be characters you move around and one should be a stationary object. Put the three characters on a list and have them move to the stationary object sliding one meter at a time. Each should stop when it gets close to the


View Full Document

TRINITY CSCI 1311 - Lists and Arrays

Course: Csci 1311-
Pages: 11
Documents in this Course
Arrays

Arrays

12 pages

Arrays

Arrays

10 pages

Applets

Applets

5 pages

Arrays

Arrays

8 pages

Methods

Methods

12 pages

Drawing

Drawing

8 pages

Load more
Download Lists and Arrays
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 Lists and Arrays 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 Lists and Arrays 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?