On this page:
1 Instructions
Practice Problems
Problem 1:   Places of Interest
Problem 2:   A Picture is worth a thousand words
8.13

Assignment 2: Designing methods for complex data🔗

Goals: Learn to design methods for complex class hierarchies. Practice designing the representation of complex data.

1 Instructions🔗

Be very, very careful with naming! Again, the testing files expect your submissions to be named a certain way, so that they can define their own Examples class with which to test your code. Therefore, whenever the assignment specifies:
  • the names of classes,

  • the names and types of the fields within classes,

  • the names, types and order of the arguments to the constructor,

  • the names, types and order of arguments to methods, or

  • filenames,

...be sure that your submission uses exactly those names. Additionally, make sure you follow the style guidelines we gave you. For now the most important ones are: using spaces instead of tabs, indenting by 2 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadlines using the course handin server. Be aware of the fact that close to the deadline the server may slow down to handle many submissions, so try to finish early. There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem you work on.

Your submissions for this homework will be organized as follows:

Due Date: Thursday, September 12, 10:00 pm

Practice Problems🔗

Work out these problems on your own. We will not collect them, but save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1: Places of Interest🔗

The following DrRacket data definition describes a simple map of places of interest:

;;A Place is a (make-place String [List-of Feature])
(define-struct place [name features])
 
;; A Feature is one of
;; -- Restaurant
;; -- Venue
;; -- ShuttleBus
 
;; A Restaurant is a (make-restaurant String String Double)
(define-struct restaurant [name type average-rating])
 
;; A Venue is a (make-venue String String Int)
(define-struct venue [name type capacity])
 
;; A ShuttleBus is a (make-shuttle-bus String Place)
(define-struct shuttle-bus [name destination])

We are giving you the names of the classes or interfaces you will probably need — make sure you use these names to define your interfaces and classes.

A reminder on naming conventions: For lists of data, the names of the interface should always start with ILo, while the two classes’ names start with MtLo for the empty lists and ConsLo for the nonempty lists; all three of these names should be followed by the name of the datatype of the elements of the list. So we would have ILoString, MtLoString, ConsLoString to represent lists of Strings, ILoBook, MtLoBook, ConsLoBook to represent lists of Books, etc.

Problem 2: A Picture is worth a thousand words🔗

Define the file Pictures.java that will contain the entire solution to this problem.

For this problem, you’re going to implement a small fragment of the image library you’ve been using for 1114 and 1115. Each picture is either a single Shape or a Combo that connects one or more pictures. Each Shape has a kind, which is a string describing what simple shape it is (e.g., "circle" or "square"), and a size. (For this problem, we will simplify and assume that each simple shape is as tall as it is wide.) A Combo consists of a name describing the resulting picture, and an operation describing how this image was put together.

There are three kinds of operations: Scale (takes a single picture and draws it twice as large), Beside (takes two pictures, and draws picture1 to the left of picture2), and Overlay (takes two pictures, and draws top-picture on top of bottom-picture, with their centers aligned).