bjc.edc.org Open in urlscan Pro
209.190.172.25  Public Scan

URL: https://bjc.edc.org/bjc-r/cur/programming/3-lists/2-contact-list/1-build-the-list.html?topic=nyc_bjc%2F3-lists.topic...
Submission: On November 21 via manual from IE — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

UNIT 3 LAB 2: CONTACT LIST, PAGE 1

 * * English
   * EspaƱol
 * 
 * * Go to Table of Contents
   * Unit 3: Data Structures
   * 
   * Lab 1: Dealing with Complexity
   * Robot in a Maze
   * Fractal Art
   * Using Abstraction to Nest Triangles
   * Brick Wall
   * Building a Tic-Tac-Toe Board
   * Debugging Recap
   * Lab 2: Contact List
   * Creating the Contact ADT
   * Adding Contact Data
   * Adding Birthdays
   * Selecting Specific Data
   * Transforming Every List Item
   * Lab 3: Tic-Tac-Toe
   * Remembering the Moves and Possible Wins
   * Detecting A Win
   * Checking for Ties
   * Lab 4: Robots and Artificial Intelligence
   * What is AI?
   * Robots and Humans
   * Implications of AI
   * Recent Breakthroughs
   * Lab 5: Computers and Work
   * Past and Future
   * Working Conditions
   * Working Remotely
   * Optional Projects
   * Curve Stitching
   * Animation Studio
   * Op Art
   * Music Project
   * Unit 3 Review
   * Vocabulary
   * On the AP Exam
   * Self-Check Questions
 * 




UNIT 3 LAB 2: CONTACT LIST, PAGE 1


CREATING THE CONTACT ADT

In this lab, you will develop a Contact List database application like the one
on your phone.

On this page, you will develop an abstract data type to store and access contact
data (name, address, phone number, etc.).

An abstract data type (ADT) is a custom data type that's meaningful to your
program. You learned about data types and ADTs on Unit 2 Lab 2 Page 2: Planning
a Quiz App.


SETTING UP THE CONTACT LIST

 1. 
 2. Create a global contact list variable.
 3. Initialize contact list as an empty list.

WHY A GLOBAL VARIABLE?

Multiple scripts across the project will use this variable, so it shouldn't be
attached to just one script like a local, script variable.


CREATING THE ADT

Jasmine and Omar are planning to build a Contact List in Snap!.
Jasmine: We need a way to add a contact to our contact list.
Omar: Each contact will be a list that with the a person's name, phone number,
address, email, or whatever we write.
Jasmine: In Unit 2, we created a quiz item abstract data type to store the
questions and answers in a list of quiz items. Here, we can make a contact
abstract data type to store the data for each contact in our list of contacts.
Omar: Yeah. In this project, we'll need a contact constructor and then selectors
to access the name, address, and phone number for any given contact.

PRESERVE PRIVACY

Snap! projects are not secure. Do not use your or your classmates' personal
information.

 4. Shortcut: You could paste the following text into the "Make a block" window
    to build the block more quickly.
    
    contact with name: %name address: %address phone: %phone
    
    The percent (%) signs make those words become input variables.
    Create a contact constructor that accepts three pieces of data as input: the
    contact's name, phone number, and address.
    
    It should report one whole contact (a list of the three items):
    
    
 5. Write the selector blocks to retrieve the name from contact, address from
    contact, or phone from contact.
    
    
    You learned about input types and output types (domain and range) on Unit 2
    Lab 3 Page 1: What's a Predicate?.
    
    It's important to make sure that your inputs to a function match the
    expected input type. For example, the input type of address from contact
    matches the output type of contact; they are both of type "contact."
    
    If you call address from contact with an input that doesn't match, such as a
    list of contacts (for example, the contact list variable or the result of
    running keep and having a subset of that list), it's not going to work. That
    may sound obvious, but in fact, beginning programmers make mistakes like
    that all the time; you have to teach yourself to think about the input and
    output types of your functions every time you write or use one.
    
    That's also true about the inputs to the contact constructor; you can't put
    something that isn't a name in the name input for contact.
    
    It's somewhat artificial to use the constructor as the input to a selector;
    these images are just examples to show what the selectors should be able to
    do when given a contact as input. In your program, the selectors will take
    an item from the contact list as input and output the correct piece of that
    contact, like this:
    

 6. Declare input types for each selector to make it obvious that they expect a
    list (one whole contact) as input.
    
    You learned about Specifying an Input Type on Unit 2 Lab 2 Page 2: Planning
    a Quiz App.
 7. Test your blocks together, and debug any problems.
    1. First, put the constructor (with input values) inside each selector (as
       shown above) to test that they each report the correct piece of data.
    2. Then, use the contact constructor to add a few contacts to your contact
       list.
       You can use these examples or make up your own:
       
       name address phone Jasmine Anderson 123 Main St. #4, New York, NY 10001
       212-555-1234 Morgan Preston 149 E. 16th Ave., Sunnyvale, CA 94089
       408-555-6789 Omar Hernandez 369 Center St., Boston, MA 02130 617-555-1098
    
    3. Notice how your contacts appear in the list.
       If you don't remember about table view and list view, revisit page 2.2.2.
    4. Try selecting the name, address, or phone from a contact in your list
       
       
    5. Debug any problems.
    AAP-1.D part b
 8. Write down how the use of an abstract data type helps manage complexity in
    your program.



The Beauty and Joy of Computing by University of California, Berkeley and
Education Development Center, Inc. is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License. The development
of this site has been funded by the National Science Foundation under grant nos.
1138596, 1441075, and 1837280; the U.S. Department of Education under grant
number S411C200074; and the Hopper-Dean Foundation. Any opinions, findings, and
conclusions or recommendations expressed in this material are those of the
author(s) and do not necessarily reflect the views of the National Science
Foundation or our other funders.