1 Instructions
Practice Problems
Problem 1
Problem 2
Problem 3

Assignment 1: Designing Data

Goals: Learn to design simple classes and classes with containment in Java. Learn to use the tester library to visualize the data and to run the tests.

1 Instructions

The names of the classes must be exactly the same as specified. The same is the case for the names and types of the fields within the class, as well as the order in which they are defined and listed as the constructor arguments. This allows us to design our own Examples class that tests your program.

Make sure you follow the style guidelines that WebCAT enforces. For now the most important ones are: using spaces instead of tabs, indenting by 4 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 deadline using the Web-CAT submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the WebCAT system may slow down to handle many submissions - so try to finish early.

With each homework you will also submit your log file named pair-user1-user2.txt where you replace user1 and user2 with the usernames of the two partners.

On top of both files you will have five lines of comments as follows:

// assignment 1

// partner1-last-name partner1-first-name

// partner1-username

// partner2-last-name partner2-firt-name

// partner2-username

(In the text file you do not need the two slashes)

Your submission sould consist of the following files:

all combined into one HW1.zip file.

Due Date: Friday, September 13th, 5:59 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 1

We are designing the data collection for the US Census Bureau. For each person we need to collect the following information:

Design the class Person that represents the information about each person for the census.

Make at least three examples of instances of this class.

Problem 2

Here is a data definition in DrRacket:

;; A IPizza is one of

;; -- Plain

;; -- Fancy


;; A Plain is

;; -- (make-plain String String)

(define-struct (plain crust cheese))


;; A Fancy is

;; -- (make-fancy IPizza String)

(define-struct (fancy base topping))

Make sure the two sample orders given above are named order1 and order2.

Name your file Pizza.java and the file and the class that holds the examples of pizza data ExamplesPizza

Problem 3

Designing methods.

Create a project with the file ExamplesAlgorithms.java given in the Lecture 1.

Note: Please, download the updated version (Sept 6 2013).

Run the program.

Design two additional static methods following the examples already shown:

Note: To test this method you need to use t.checkInexact(actual, expected, tolerance) where the tolerance is relative between the actual and expected values.