Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
