1 Instructions
Practice Problems
Problem 1
Problem 2
Problem 3
Version: 5.3.0.10

Assignment 2

Goals: Review the design recipes, work with inexact numbers, review the design of loops using the accumulator style.

1 Instructions

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.

You will submit this assignment by the deadline using the Web-CAT submission system. We will be practicing its use during the lab next week.

With each homework you will also submit your log file named pairxx.txt where you replace xx with your pair number.

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

// assignment 2

// pair xxx

// 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:

Combine all files into one HW2.zip file and submit that file.

Due Date: Tuesday, January 22nd, 11: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

Finish working out the problem from Lab 2 that deals with a phone chain for a soccer team.

Name the file you submit IPhoneChain.java and the file and the class that holds the examples of phone chain data ExamplesPhoneChain.java.

At the end of your ExamplesPhoneChain class definition include the following lines:

// making sure the code contains at least one test

boolean testAll(Tester t) {

  ExamplesPhoneChain epc = new ExamplesPhoneChain();

  return t.checkExpect(epc.jenLink, epc.jenLink);

}

This is only needed for our first two submissions, because they do not contain any tests.

Problem 2

Here is a data definition in DrRacket:

;; An IPizza is one of

;; -- (make-plain String String)

;; -- (make-fancy IPizza String)

 

(define-struct (plain crust cheese))

(define-struct (fancy base topping))

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

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

At the end of your ExamplesPizza class definition include the following lines:

// making sure the code contains at least one test

boolean testAll(Tester t) {

  ExamplesPizza ep = new ExamplesPizza();

  return t.checkExpect(ep.order1, ep.order1);

}

This is only needed for our first two submissions, because they do not contain any tests.

Problem 3

Designing methods.

Make sure the objects that represent the four sample persons are named ann, pat, kim, and dan, and the name of your method is sameCity.

Name your file Person.java and the file and class that holds the examples of peron and address data ExamplesPerson.java