©2008 Felleisen, Proulx, et. al.

2  Understanding Data

Portfolio Problems

Pair Programming Assignment

Graphs

All problems in this part become one Beginner ProfessorJ program. Combine all examples of data into one Examples class.

Most of these problems ask you to translate data definitions and examples from Beginner HtDP language to Beginner ProfessorJ language, to add class diagrams that represent these data definitions, and to convert the examples of data to the Beginner ProfessorJ language.

Draw the class diagram for each problem as you go. The diagrams should grow as we add more classes and interfaces that refer to each other through containment arrows and inheritance arrows. Make sure you use these arrow correctly.

2.1  Problem

Design the data definition in ProfessorJ Beginner language for the class CartPt that represents a location on a Canvas using the x, y coordinates, where x and y are whole (non-negative) numbers. Solution

2.2  Problem

Design the data definition in ProfessorJ Beginner language for the class
SimpleNode that represents a node in a graph. Each node has a name (one or more characters, usually letters and digits) and a location (a cartesian point so that it can be drawn on a CanvasSolution

2.3  Problem

Design the data definition in ProfessorJ Beginner language for the class Edge that represents an edge in a graph. Each edge is defined by the names of the two nodes, its origin and its target node. Solution

2.4  Problem

Design the data definition in ProfessorJ Beginner language for the classes and interfaces that represent a list of Strings.

Hint: Think of names such as ILoString, MtLoString, and ConsLoStringSolution

2.5  Problem

Develop the data definitions in ProfessorJ Beginner language for the class Node that includes not only the information required for the class SimpleNode, but also includes a list of the names of all neighbors of this node. Solution

2.6  Problem

Develop the data definitions in ProfessorJ Beginner language that represent all information needed to draw a graph as we have done in Assignment 1. Include a class diagram. Name your class GraphSolution

2.7  Problem

Add to your examples two examples of graph that represent the same information as the two examples in Assignment 1 (the graph given there, and your new example graph). Solution

City Map

2.8  Problem

Translate the class diagram in figure 1 into a class definition. Also create instances of the class. Include among your examples the data that represents the locations on the enclosed map (figure 2). The grid lines are 20 pixels apart. Solution


                     +---------------+                     
                     | InterestPoint |                     
                     +---------------+                     
                     +---------------+                     
                             |                             
                            / \                            
                            ---                            
                             |                             
         ----------------------------------------          
         |                   |                  |          
  +--------------+    +-------------+    +--------------+  
  | Hotel        |    | Museum      |    | Hospital     |  
  +--------------+    +-------------+    +--------------+  
  | String name  |    | String name |    | String name  |  
+-| Place loc    |  +-| Place loc   |  +-| Place loc    |    
| | String phone |  | | String kind |  | | boolean er   |  
| +--------------+  | | String url  |  | +--------------+  
|                   | +-------------+  |   
|    +--------------+                  |
+--+ | +-------------------------------+                    
   | | |                                                      
   v v v
+-------+
| Place |
+-------+
| int x |
| int y |
+-------+

Figure 1: A class diagram for city map points of interest

[ex2-Z-G-1.gif]

Hotel California
Hotel Baltimore
Museum of Fine Arts
Paul Revere House
Mercy Hospital
Lazarus Hospital

Figure 2: A sample city map

Last modified: Wednesday, January 16th, 2008 8:45:44am