Question
1. Change the width of the box to 30 and change the height of the box to 50 by using the following method. setSize(int width,
1. Change the width of the box to 30 and change the height of the box to 50 by using the following method.
setSize(int width, int height)
2. Remove the translate method from the code.
3. Get and print the new width and height of the rectangle. Hint*: Use the getWidth() and getHeight()methods.
4. Also print the expected answer.
import java.awt.Rectangle;
public class MoveTester { public static void main(String[] args) { Rectangle box = new Rectangle(5, 10, 20, 30);
// Move the rectangle box.translate(15, 25);
// Print information about the moved rectangle System.out.print("x: "); System.out.println(box.getX()); System.out.println("Expected: 20");
System.out.print("y: "); System.out.println(box.getY()); System.out.println("Expected: 35"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started