CS 2102 - Bterm 08

Homework 2 - Class Definitions

Due: Tuesday, November 4 at 11:59pm

Assignment Goals


The Assignment

All problems in this assignment should be included in a single 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, and to add class diagrams that represent these data definitions.

Draw the class diagram for each problem as you go. The diagrams should grow as you add more classes and interfaces that refer to each other through containment arrows and inheritance arrows. Make sure you use these arrow correctly. You may either draw the class diagrams on paper and hand the paper in at the beginning of class on Tuesday, Nov 4, or you may include the class diagrams by drawing text pictures in your Scheme file and turn them in with your problem set at the regular 11:59pm turnin due date.

Problems

  1. Open DrScheme and change the Language to Beginner ProfessorJ. Design the (Java) data definition for the class CartPt that represents a location using x, y coordinates, where x and y are whole (non-negative) numbers.

  2. Design the data definition 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).

  3. Design the data definition for the class Edge that represents an edge in a graph. Each edge is defined by the names of its source and target nodes.

  4. Design the data definition for the classes and interfaces that represent a list of Strings. (Hint: Think of names such as ILoString, MtLoString, and ConsLoString.)

  5. Develop the data definitions 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.

  6. Develop the data definitions that represent all information needed to draw a graph, as we did in Homework 1. Include a class diagram. Name your class Graph.

  7. Add to your Examples class an example of a graph that represents the graph pictured in Homework 1.

  8. Here is a class diagram:
                         +---------------+                     
                         | InterestPoint |                     
                         +---------------+                     
                         +---------------+                     
                                 |                             
                                / \                            
                                ---                            
                                 |                             
             ----------------------------------------          
             |                   |                  |          
      +--------------+    +-------------+    +--------------+  
      | Hotel        |    | Museum      |    | Hospital     |  
      +--------------+    +-------------+    +--------------+  
      | String name  |    | String name |    | String name  |  
    +-| CartPt loc   |  +-| CartPt loc  |  +-| CartPt loc   |    
    | | String phone |  | | String kind |  | | boolean er   |  
    | +--------------+  | | String url  |  | +--------------+  
    |                   | +-------------+  |   
    |    +--------------+                  |
    +--+ | +-------------------------------+                    
       | | |                                                      
       v v v
    +-------+
    | CartPt|
    +-------+
    | int x |
    | int y |
    +-------+ 
    
    Translate the class diagram into a class definition. Create an instance of the class that represents the locations on the following map. The grid lines are 20 pixels apart.

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

    What to Turn In

    Using web-based turnin, turn in a single file hw2.bjava containing all code and documentation for this assignment. Both partners' names and wpi login names should appear in a comment at the top of the file.