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 2.4 on page 17
Problem 3.1 on page 25
Problem 4.4 on page 33
Problem 5.3 on page 44
Problem 5.9 on page 51
Problem 10.2 on page 97
Problem 10.5 on page 105
Problem 14.1 on page 140
Problem 14.7 on page 144
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)) |
Draw the class diagram that represents this data definition.
Convert this data definition into Java.
Include in your examples the following two piza orders:
– a pizza with thin crust, mozarella cheese, and two toppings: mushrooms and olives
– a deep dish pizza with mixed cheese, pepperoni, and onions
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