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

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 every file you submit you will have the names of both partners, and the pair number.

The .txt file will be the log of your work on this assignment. Each log entry will have data and time, who was present (one or both of the partners) and a short comment decribing what you were working on.

Due Date: Thursday, September 20th, 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

Convert the data definition for a maze from the first lab and assignment into Java classes and interfaces.

Include in your examples the data that represents the following maze of questions:

Q1: "Do you like water?"

  yes: Q2: "Do you like boating?"

  no:  Q3: "Are you afraid of the dark?"

 

Q2:

  yes: Q4: "Can you swim?"

  no:  Q5: "Are you a sailor?"

 

Q3:

  yes: Q6: "Do loud noises scare you?"

  no:  Q7: "Are you afraid of heights?"

 

Q4:

  yes: A8: "Water is a good thing!"

  no:  A9: "Go jump in a lake!"

 

Q5:

  yes: A10: "Ahoy!"

  no:  A11: "Go paddle!"

 

Q6:

  yes: Q12: "Can you hear the wind?"

  no:  A13: "Play a song!"

 

Q7:

  yes: A14: "Do not climb a tall waterfall at night!"

  no:  A15: "Learn to swim!"

 

Q12:

  yes: A16: "BOO!"

  no:  A17: "Hide, the wind is blowing!"

Make sure the object that represents the entire maze is named q1

Name your Examples class ExamplesMaze

Problem 2

Here is a data definition in DrRacket:

;; A Pizza is one of

;; -- (make-plain String String)

;; -- (make-fancy Pizza 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 Examples class ExamplesPizza

Problem 3

Complete and hand in the Part 7 of Lab 2 that asks you to design your first method(s).

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

Name your Examples class ExamplesPersonAddress