## 2.1  Understanding Data: Simple Classes

In this lab we will focus on understanding data definitions, the distinction between information and data, how information can be represented as data, how to interpret the information that some instance of data represents, and learn to encode the data definitions, as well as construct instances of data in a class based language (like Java).

Look at the following data definitions in the Beginner Student HtDP language:

```;; Sample data definitions -- simple classes of data

;; to represent a pet
;; A Pet is (make-pet String Num String)
(define-struct pet (name weight owner))

;; Examples of pets:
(define kitty (make-pet "Kitty" 15 "Pete"))
(define spot (make-pet "Spot" 20 "Jane"))
```

1. Draw the class diagram for this data definition.

2. Convert the data definition to the Beginner ProfessorJ language — including the examples of data.

If you are comfortable with this material, you may omit the next two questions.

3. Convert the following class diagram into Beginner ProfessorJ language:

```  +--------------+
| Restaurant   |
+--------------+
| String name  |
| String kind  |
| int avgPrice |
+--------------+
```

4. Convert the following information to data examples for your Restaurant class.

• Chinese restaurant Blue Moon with average price per dinner \$15

• Japanese restaurant Kaimo with average price per dinner \$20

• Mexican restaurant Cordita with average price per dinner \$12

## 2.2  Understanding Data: Classes with Containment

Look at the following data definitions in the Beginner Student HtDP language:

```;; to represent a pet
;; A Pet2 is (make-pet String Num Person)
(define-struct pet2 (name weight owner))

;; to represent a person - a pet's owner
;; A Person is (make-person String Num Boolean)
(define-struct person (name age male?))

;; Examples of person data:
(define pete (make-person "Pete" 15 true))
(define jane (make-person "Jane" 19 false))

;; Examples of pet2 data:
(define kitty2 (make-pet "Kitty" 15 pete))
(define spot2 (make-pet "Spot" 20 jane))
```

1. Draw the class diagram for this data definition.

2. Convert the data definition to the Beginner ProfessorJ language — including the examples of data.

If you are comfortable with this material, you may omit the next two questions.

3. Convert the following class diagram into Beginner ProfessorJ language:

```  +--------------+
| Restaurant2  |
+--------------+
| String name  |
| String kind  |
| int avgPrice |
| CartPt loc   |--+
+--------------+  |
v
+--------+
| CartPt |
+--------+
| int x  |
| int y  |
+--------+
```

4. Make new examples for your Restaurant2 class.