Assignment 2     ©2011 Felleisen, Proulx, Chadwick, et. al.

Designing Classes

 

Due: 1/25/2011 @ 10:00pm

Portfolio Problems

Work out as the following exercises from the textbook. Do not add them to your assignment submission, though you should keep them in your electronic portfolio in a separate directory of your pair’s repository, e.g., Portfolio-02.

Problems:

  1. Problem 2.4 on page 17

  2. Problem 3.1 on page 25

  3. Problem 4.4 on page 33

  4. Problem 5.3 on page 44

  5. Problem 5.9 on page 51

  6. Problem 10.2 on page 97

  7. Problem 10.5 on page 105

  8. Problem 14.1 on page 140

  9. Problem 14.7 on page 144

Pair Programming Assignment

These problems should be checked into your pair’s SVN repository under the directory named Assignment-02 by the due date. See the individual problems for file naming requirements.

2.1  Problem

Answers to this problem should be placed in a Java file named Cities.java, in the Assignment-02/src directory of your pair’s Trac/SVN repository. Name your examples class CityExamples.

  1. Convert your data representation for US cities from the previous assignment into data definitions in the FunJava language. (i.e., create a class City)

  2. Make sure you have a separate class Loc for the location coordinates in latitude and longitude

  3. Define a class hierarchy that represents a list of cities. Follow the DESIGN RECIPE FOR DATA DEFINITIONS. Remember to make examples of data in a CityExamples class.

2.2  Problem

Answers to this problem should be placed in a Java file named Lunches.java, in the Assignment-02/src directory of your pair’s Trac/SVN repository. Make sure the examples class is named different than the problem above (e.g., LunchExamples).

Design the classes (i.e., a class hierarchy) to represent lunch orders. For lunch a customer can choose a soup (soups have different flavors), a salad (one of several kinds, as well as a choice of several choices of dressings), and a sandwich. For a sandwich the customer selects the bread, the filling, and a list of extras (tomatoe, onion, mayo, mustard, olives, etc.). For each of the lunch parts we need to know whether or not they are vegetarian.

The restaurant charges individually for each selection, but all breads cost the same and each of the extras costs the same. There is no extra charge for dressing on the salad.

  1. Make examples of at least two of each: soup, salad, dressings, breads, fillings, extras.

  2. Make at least four examples of lunches where at least one of them must be vegetarian.

  3. The class that represents the entire lunch order should be named Lunch. You can name all the other classes as you wish, but make sure your names are sensible and that your class names start with a capital letter.

Last modified: Tuesday, January 18th, 2011 4:35:52pm