Recitation 1: Simple Data Definitions in Java
Goals: Create a Java project from the course template, run supplied tests, and translate familiar data definitions into Java classes and interfaces. Recitation 0 must be complete before beginning this work.
The core work below is sized for one 75-minute meeting. The final section preserves additional exercises from the older three-meeting-per-week version of the course; complete those only when the instructor assigns them.
1 Create the Shapes project
Open IntelliJ and create a project from the CSAS2123 template saved in Recitation 0. Name the project Shapes.
Open File > Project Structure > Project. Confirm that the project SDK is a JDK 11 and the language level is 11. If the project refers to an SDK that exists only on another computer, select an installed JDK 11 or choose Download JDK, Version 11, with any available vendor. The SDK’s local name and path do not need to match anyone else’s.
Download Shapes.java from the link above and place it in the project’s blue src directory.
Open Run > Edit Configurations. Select the Course Tests configuration and set its program arguments to ExamplesShapes.
Run the configuration. Resolve any project, JDK, or library problem before changing the supplied Java file.
2 Read a Java data definition
One of our familiar forms of data is a union: an enumeration, itemization, or collection of related alternatives. In Java, the supplied file represents a union with an interface and represents each alternative with a class that implements that interface.
In Shapes.java, locate:
the IShape interface,
the classes that implement IShape,
the fields and constructors in each class, and
the examples constructed in ExamplesShapes.
You are not expected to know every piece of Java syntax yet. Relate each part of the file to the data-definition templates discussed in class and ask about anything you cannot identify.
Add examples representing the shapes in the following image. Ignore the colors. Give each example the interface type IShape and construct it with the appropriate concrete class.

Run ExamplesShapes again after adding the examples.
3 Core translation exercises
3.1 Problem 1: Simple data
Here is a familiar data definition:
;; A Person is (make-person String Number String) (define-struct person [name age gender]) (define tim (make-person "Tim" 23 "Male")) (define kate (make-person "Kate" 22 "Female")) (define rebecca (make-person "Rebecca" 31 "Non-binary"))
Draw the class diagram for this data.
In a new Person.java file, define a Person class with fields and a constructor corresponding to the definition above.
Define an ExamplesPerson class containing the three examples.
Change the Course Tests program argument to ExamplesPerson and run it.
3.2 Problem 2: Containment
Modify the definition so that each person also has an address. An address records a city and a state, each in its own field.
Draw the revised class diagram.
Define an Address class and revise Person to contain an Address.
Tim lives in Boston, MA; Kate lives in Warwick, RI; and Rebecca lives in Nashua, NH. Revise those examples and add two people of your own.
Run ExamplesPerson again.
Stop here unless the instructor assigns additional practice.
4 Additional practice from the longer course format
4.1 Problem 3: A union of data
A deli menu includes soups, salads, and sandwiches. Every item has a name and a price in cents. Each soup and salad records whether it is vegetarian. A salad also records the name of its dressing. A sandwich records its bread and two fillings; ignore condiments and other extras.
Draw a class diagram for the menu-item union.
Define the interface and classes that represent the data. Decide the type of every field before writing constructors.
Construct at least two examples of each kind of menu item.
4.2 Problem 4: Self-reference
The HtDP book uses this definition for ancestor trees:
;; An AncestorTree is one of: ;; -- 'unknown ;; -- (make-tree Person AncestorTree AncestorTree)
Convert the definition into Java classes and interfaces. Make examples in which at least one branch covers three generations. Be prepared to explain the Java representation you chose for ’unknown.