Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA public class Rectangle{ int x,y,w,h; // Constructor public Rectangle(int x, int y, int w, int h){ } // A shift of the initial 5,5
JAVA public class Rectangle{ int x,y,w,h; // Constructor public Rectangle(int x, int y, int w, int h){ } // A shift of the initial 5,5 to the new x,y positions public void translate(int x, int y){ } // Calculate and return the area of the rectangle public int area(){ } // Calculate and return the perimeter of the rectangle public int getPerimeter(){ } // Retun the width of the rectangle public int getWidth(){ } // Return the height of the rectangle public int getHeight(){ } // Return the x coordinate of the rectangle public int getX(){ } // return the y coordinate of the rectangle public int getY(){ } // This is the main() method, entry point to the program public static void main(String[] args){ //initialize Rectangle object Rectangle box = new Rectangle(5,5,5,5); //translation System.out.println("Location: " + box.getX() + ", " + box.getY()); box.translate(5,5); System.out.println("Location after Shift: " + box.getX() + ", " + box.getY()); //general info System.out.println("Height: " + box.getHeight()); System.out.println("Width: " + box.getWidth()); System.out.println("Area: " + box.area()); System.out.println("Perimeter: " + box.getPerimeter()); } }
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