Assignment 2: Designing methods for complex data
Goals: Learn to design methods for complex class hierarchies. Practice designing the representation of complex data.
Instructions
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,
You will submit this assignment by the deadlines using the course handin server. Follow A Complete Guide to the Handin Server for information on how to use the handin server. You may submit as many times as you wish. 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.
Remember that you should avoid accessing fields of fields and using any type-checkers. Design your methods systematically using the Design Recipe as we have been doing in class!
Part 1: Monday, September 18th, 9:00 pm
Part 2: Thursday, September 21st, 9:00 pm
Practice Problems
Work out these problems on your own. 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 10.6 on page 102
Problem 11.2 on page 113
Problem 12.1 on page 125
Problem 14.7 on page 140
Problem 15.2 on page 149
Problem 15.3 on page 149
Problem 15.8 on page 171
Problem 1: Places of Interest
You will submit this in two parts:
Part 1: Submit your data definitions, examples and tests for the foodinessRating and restaurantInfo methods. You should include stubs for the two methods themselves. This will be partly graded on the completeness of your test cases. You may add examples if there are cases you want to test that are not covered by the examples described below. Please add a comment for each test case describing what you are testing.
Part 2: Submit everything from Part 1 but this time include complete implementations for the methods (including any helpers needed).
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-bus String Place) (define-struct bus (name destination))
We are giving you the names of the classes or interfaces you will probably need
—
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.
Note: if it helps you at all in this assignment, you may assume that every name in this place-map is distinct.
Draw a class diagram for the classes that represent this data definition. (It is optional to submit your diagram. You can draw this on paper, or in ASCII art as a comment in your submitted file.)
Define Java classes that represent the definitions above.
Name your examples class ExamplesPlaces
In the ExamplesPlaces class design the example of the following:The places are real; the transports are fictitious.
- A place named "CambridgeSide Galleria", with the following features:
A "teriyaki" restaurant named "Sarku Japan", with rating of 3.9 stars
A "coffee" restaurant named "Starbucks", with a 4.1 rating
A "bridge shuttle" bus to South Station
- A place named "South Station", with the following features:
The "Little Italy Express" shuttle to the North End
"Regina's Pizza" restaurant, that sells "pizza", rated 4.0
The "Crimson Cruiser" shuttle to Harvard
"Boston Common", a "public" venue with capacity for 150,000.
- A place named "North End", with the following features:
The "TD Garden" "stadium" venue, with capacity 19,580.
"The Daily Catch", a 4.4-star restaurant selling "Sicilian"
- "Harvard", with the following features:
A "Freshmen-15" shuttle to the North End
"Border Cafe", a 4.5-star "Tex-Mex" restaurant
"Harvard Stadium", a "football" venue with seating for 30,323
Name the "CambridgeSide Galleria" example cambridgeSide. Our test program will check that the field cambridgeSide in the class ExamplesPlaces represents this information. (You may name the other places, and all the items inside them, anything you like, though the names should be reasonably descriptive.)
Design the method foodinessRating that computes the average rating of all the restaurants’ ratings, for all the restaurants reachable from the current place.
Hint: you will need some helper methods for this...
Tricky! Design the method restaurantInfo that produces one String that has in it all names of restaurants reachable from a place, their food types in parentheses, and each restaurant separated by comma and space.
So for the CambridgeSide Galleria example above this String would be
"Sarku Japan (teriyaki), Starbucks (coffee), The Daily Catch (Sicilian), Regina's Pizza (pizza), The Daily Catch (Sicilian), Border Cafe (Tex-Mex)"
Note: You can combine two Strings with a + operator, or by invoking the method concat: assuming both s1 and s2 are Strings, then both s1 + s2 and s1.concat(s2) do the same thing as the BSL expression (string-append s1 s2). Do not use substring for this method.
Note: There is a comma and space between any two entries, but not after the last one.
In a comment in your file, explain why some methods double-count some information. Also tell us if there are any other methods in your code where this duplication occurs. Hint: look very carefully at the output from the tester library when it shows your data.