Question: Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 4 ) - Create a directory named as the question number and save the required

Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 4)

- Create a directory named as the question number and save the required solutions in the directory.

- Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester.

Exercise 4.15

ZoomTester.java

Write a program that shows a frame with two buttons labeled Zoom in, and Zoom out, and a label containing a car icon. As the user clicks the buttons, the car should get larger or smaller. As in Exercise 14, you need to invoke the repaint method on the label to trigger a redisplay of the image.

CarShape.java

import java.awt.*; import java.awt.geom.*; import java.util.*; /**  A car that can be moved around. */ public class CarShape implements MoveableShape { /**  Constructs a car item.  @param x the left of the bounding rectangle  @param y the top of the bounding rectangle  @param width the width of the bounding rectangle  */ public CarShape(int x, int y, int width) { this.x = x; this.y = y; this.width = width; } public void move() { x++; } public void draw(Graphics2D g2) { Rectangle2D.Double body = new Rectangle2D.Double(x, y + width / 6, width - 1, width / 6); Ellipse2D.Double frontTire = new Ellipse2D.Double(x + width / 6, y + width / 3, width / 6, width / 6); Ellipse2D.Double rearTire = new Ellipse2D.Double(x + width * 2 / 3, y + width / 3, width / 6, width / 6); // The bottom of the front windshield Point2D.Double r1 = new Point2D.Double(x + width / 6, y + width / 6); // The front of the roof Point2D.Double r2 = new Point2D.Double(x + width / 3, y); // The rear of the roof Point2D.Double r3 = new Point2D.Double(x + width * 2 / 3, y); // The bottom of the rear windshield Point2D.Double r4 = new Point2D.Double(x + width * 5 / 6, y + width / 6); Line2D.Double frontWindshield = new Line2D.Double(r1, r2); Line2D.Double roofTop = new Line2D.Double(r2, r3); Line2D.Double rearWindshield = new Line2D.Double(r3, r4); g2.draw(body); g2.draw(frontTire); g2.draw(rearTire); g2.draw(frontWindshield); g2.draw(roofTop); g2.draw(rearWindshield); } private int x; private int y; private int width; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!