Adding Birthdays

Purpose (do/learn; why this/here): Extend the ADT by adding a date ADT, adapting the contact ADT to accept it, and adding more helper blocks.

Can we cut all the commented out text on this page? --MF, 7/22/19

MARY: change the DATE ADT to use the correct ADT format. --MF, 5/23/20

BRIAN: as a low priority (that is, after ALL the solutions for all units and all optional projects are done), you want to add a "parse a date" TIF. --MF, 5/23/20

On this page, you will develop an abstract data type (ADT) to store and access dates, and you will adapt your contact ADT to use it to store each contact's birthday.
contact with name: ... birthday: (date (July) (9) (2005))

As we add more complexity to contacts—birthday, work address, and so on—the location of each data point (such as the phone number) inside a contact might change. This is where an abstract data type helps. If you were to move the phone number as you refine your contact ADT, you could fix every single block that uses the phone number, or if you have an ADT, you could just fix the one selector that chooses the phone number from the list. With that one change, all the other blocks using that selector will get the data they need automatically.

AAP-1.D.5

Notice that name, address, and text are strings, but birthdate is a list. You can combine elements of different types in a list.

  1. Create an ADT to manage three data points for each date: month, day, and year.
    1. Create a date constructor that accepts this data as input and then reports a date as a list of three items.
      date (July) (9) (2005) reporting {July, 9, 2005}
    2. Write three selector blocks to retrieve the specific data (month, day, or year) from the inputted date.
      month from date: () reporting July day from date: () reporting 9 year from date: () reporting 2005
    3. Debug any problems with the constructor or selectors.
  2. Integrate your date ADT into the contact ADT.
    • Edit the contact constructor block definition to accept a birthdate as a list by using the date constructor.
      contact with name: (Betsy) address: (123 Main St., New York NY 10001) phone: (212-555-1234) birthdate: (date (July) (9) (2005)) reporting {Betsy, 123 Main St., New York NY 10001, 212-555-1234, {July, 9, 2005}}
    • Create a birthdate from contact selector to retrieve the contact birthdate from the inputted contact.
      birthdate from contact: (contact with name: (Betsy) address: (123 Main St., New York NY 10001) phone: (212-555-1234) birthdate: (date (July) (9) (2005))) reporting {July, 9, 2005}
    • Adapt your "Add Contact" button to input this new type of contact into your list.

      Adding Contacts with Birthdays

      You could use several ask and answer blocks together with script variables.

      Another way is to use abstraction and create another helper, ask birthdate that reports a list of the user's answers to these prompts:

      • What is the contact's birth month?
      • What is the contact's birth day?
      • What is the contact's birth year?
      contact with name: (ask name) address: (ask address) phone: (ask phone) birthdate: (ask birthdate)

  3. Save Your Work
  4. Debug. Clear your contact list, and add a new few contacts with birthdays. Fix any problems.