Assignment 3
Goals: Learn how to follow the design recipe for designing methods in Java.
As the part of the design recipe, learn how to design tests for the methods and how to run them.
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 pairxxx.txt where you replace xxx 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 27th, 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 10.6 on page 105
Problem 11.2 on page 116
Problem 12.1 on page 129
Use the javalib libraries to draw a stick figure
Problem 14.7 on page 144
Problem 1
The following DrRacket data definition describes the contents of a web site:
;;A Web Page (WP) is (make-wp String String [Listof Item (ILoI)]) |
(define-struct wp (url title items)) |
|
;; An Item is one of |
;; -- Text |
;; -- Image |
;; -- Link |
|
;; A Text is (make=text String) |
(define-struct text (contents)) |
|
;; An Image is (make-image String int String) |
(define-struct image (file-name size file-type)) |
|
;; A Link is (make-link String WP) |
(define-struct link (name page)) |
We are giving you the names of the classes or interfaces you will probably need
—
For lists of data, the names of the two classes should be always starting with Mt for the empty lits and Cons for the nonempty lists.
Describe in English, on paper a web page with at least two of each kind of items and at least two levels of links.
Draw a class diagram for the classes that represent this data definition.
Define Java classes that represent web pages as defined above.
Design the data representation of the example you have defined earlier.
Design the example of the following web page:
WP: with title "My Pets" at url "mypets.org"
that contains the following items:
-- text "This is my dog"
-- image of the dog in the file "doggie" of size 230 and file type "jpeg"
-- text "This is my cat"
-- image of the cat in the file "kitty" of size 400 and file type "png"
-- link with the label "Here are Bob's pets" to the web page named "Bob's Pets"
WP: with the title "Bob's Pets" at url "bob-pets.org"
that contains the following items:
-- text "My gerbil"
-- image of the gerbil in the file "cutie" of size 300 and file type "png"
Design the method totalImageSize that computes the total size of all images in this web page and all web pages that are linked to it.
Design the method textLength that computer the number of letters in all text that appears on the web site starting at this web page. This includes the contents of the text, the names of the image files, the labels for links, and their titles of the web pages.
Design the method images that produces one String that has in it all names of images on this web site, given with their file types, and separated by comma and space.
So for the exmple above this String would start with
"doggie.jpeg, kittie.png"
Note: You can combine two Strings with a + operator, or by invoking the method concat (e.g. s1.concat(s2) produces a new String appending the String s2 to the String s1.)
Make sure the object that represents the the "My Pets" page is named myPetsWP
Name your Examples class ExamplesWP
Problem 2
Continue the work on the Mobiles from the lab 3.
Make an example of the following mobile:
|
|
|
------------+------
| |
------+------ |
| | |
10 | 40
red 10 green
blue
Name it calder.
Finish the work on designing the methods isBalanced and buildMobile from the lab and include it in your submission.
Design the method mobileImage that produces a WorldImage that represents this mobile.
Make sure the object that represents the shown mobile is named calder, and the name of your methods are isBalanced, isBalbuildMobileanced, and mobileImage.
Name your Examples class ExamplesMobiles