You will hear the the following said frequently this semester: there is no right or wrong design; however, there are good and bad designs. In other words, many designs can serve to solve a particular problem. But each design may have its own strengths and weaknesses. This is also true of the design you have before you for this lab. After considering it, you may come up with improvements. Feel free to talk about these with your TAs or instructor. Improvements are always welcome!
All labs will include a main file named by the lab number,
Lab2.java. The labs will
also include a
Startup.java file, which
serves as a driver: a piece of code that calls the methods you
write, to exercise your code and demonstrate your work.
Recall that the following lines should appear at the top of any files that use the terminal or canvas classes.
import terminal.*; import canvas.*;
A set of cartoon characters has been trying for some time to purchase clothing. However, when they shop, the merchant doesn't take them seriously for the following reasons.
.com. This store allows the characters to order clothing discreetly and electronically.
One concern these customers have is the changes their garments suffer when laundered. Even two-dimensional clothing suffers expansion when washed and shrinkage when dried. The customers would like to simulate the wash and dry cycles and see the resulting effects on their garments.
Our problem is to provide a means for
CS101Canvasto display the garment and interact with the user.
Rectclass, for which we have the following API.
The corner designated internally as (c1x, c1y) is considered its origin. The other corner, (c2x, c2y) is diagonally opposite the origin corner.
(c1x, c1y) |----------------------------| | | | | | | | | |----------------------------| (c2x, c2y)
int getC1X()returns the x coordinate of the rectangle's current origin.
int getC1Y()returns the y coordinate of the rectangle's current origin.
int getC2X()returns the x coordinate of the rectangle's other corner.
int getC2Y()returns the y coordinate of the rectangle's other corner.
int getWidth()returns the current width of the rectangle.
int getHeight()returns the current height of the rectangle.
void relocateTo(int x, int y)
void scale(double sx, double sy)
void setWidth(int width)
void setHeight(int height)
private void update()
Shirt(CS101Canvas canvas, int trunkWidth, int trunkHeight, double sleeveFrac, double trimFrac, double washScale, double dryScale)
trunkHeightare the width and height of the trunk of the shirt, prior to any laundering.
sleeveFracis the scale of the sleeve with respect to the shirt. For example, a
sleeveFracof 0.5 would create a sleeve whose width and height are one-half the size of the trunk.
trimFracis the scale of trim with respect to the size of the object it trims. However, the scale only applies to the appropriate dimension. For a shirt sleeve, the trim is the same height as the sleeve, but the trim's width is affected by
dryScalespecify the factors by which the garment scales when washed and dried, respectively.
void wash()affects the garment by one wash cycle.
void dry()affects the garment by one dry cycle.
Sleeve, we have the following API.
Sleeve(CS101Canvas canvas, double frac, double trimFrac)
fracis the fraction of the trunk for this sleeve. This is fixed at construction time, even though no sleeve is drawn yet.
trimFracis the fraction of this sleeve that the trim should occupy, as described for
void become(int x, int y, int trunkWidth, int trunkHeight)update's the sleeves origin to (x,y). The trunk's current width and height are provided, so that the sleeve can compute its current dimensions.
Trim, we have the following API.
Trim(CS101Canvas canvas, double frac)
fracis the fraction of the garment's component for this trim. This is fixed at construction time, even though no sleeve is drawn yet.
void become(int x, int y, int sleeveWidth, int sleeveHeight)update's the trim's origin to (x,y). The sleeve's current width and height are provided, so that the trim can compute its current dimensions.
You must implement the classes described in the design. For this lab, you are constrained to following this design. Specific implementation steps are given at the end of this document; the files you download repeat those suggestions.
(The files contain some more specific instructions.)
Rect.javaaccording to the instructions contained in that file.
testRectcode provided in
Shirt.java, but just to the point of getting the trunk of the shirt drawn.
testShirtcode provided in
Sleeve.javaand continue testing.
Trim.javaand continue testing.