copyright 2012 Felleisen, Proulx, et. al.

CS 2510 Spring 2012: Assignment 2 - Data Definitions

Practice 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-myName-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 by the due date.

Project naming requirements

The names of the projects and some of the project files must be exactly the same as specified in the assignment. Failure to do so makes it impossible for the graders to run your submission and results in immediate loss of at least 50% of the homework credit.

Make sure you follow the style guidelines for code indentation.

Problem 1

Create a project with the name HW02Problem1. Your java file must be named Cities.java and the Examples class inside this file must be named ExamplesCities.

  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

    To represent numbers that are not integers, please use Java double primitive data type.

  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 the ExamplesCities class.


Problem 2

Create a project with the name HW02Problem2. Answers to this problem should be placed in a Java file named Lunches.java and the Examples class inside this file must be named ExamplesLunches.

The goal of this problem is to give you some design freedom, to make you think about the information and how it can be represented as data.

Design the classes (i.e., a class hierarchy) to represent lunch orders in a soup and salad bar. 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 bread. For each of the lunch parts we need to know whether or not they are vegetarian.

Note: Salad dressing can be non-vegetarian, for example if they contain bacon bits. There are varieties of breads one can ask for, such as rolls, whole wheat bread, bread sticks, or Hungarian Bacon Biscuits (Pogacsa) --- yes, they contain bacon or chitterlings.

The restaurant has different prices for every soup and for every salad, but all breads cost the same and there is no extra charge for dressing for the salad.

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

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

    Note:Make these examples as if you were actually ordering the lunch, i.e., write down on a piece of paper the information you are hoping to represent in your code. Use these notes later to guide you in designing exmples of data for your data definitions.

  3. Now design the class that represents the entire lunch order, this class should be named Lunch. Of course, you will need several other classes, maybe a union of classes, maybe a class that references another class, etc. You can name all the other classes and interfaces as you wish, but make sure your names are sensible and that your class names start with a capital letter and the interface names start with the capital letter I.

  4. Convert your original examples of lunch orders into data in the ExamplesLunches class.


Last modified: Wed Jan 18 11:15:14 EST 2012