Answered step by step
Verified Expert Solution
Question
1 Approved Answer
RectangleFu... X 1 2 import java.awt. Rectangle; W N 3 import java.util.Scanner; 4 5 public class RectangleFun 6 { 7 8 9 10 HANGGA998HNEN
RectangleFu... X 1 2 import java.awt. Rectangle; W N 3 import java.util.Scanner; 4 5 public class RectangleFun 6 { 7 8 9 10 HANGGA998HNEN EN BA 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 public static void main(String[] args) { Terminal Scanner kb = new Scanner (System.in); System.out.print("Width: "); int w = kb.nextInt(); System.out.print("Height: "); int h kb. nextInt (); System.out.print("X: "); int x int y = System.out.print("Y: "); kb.nextInt(); kb.nextInt(); // Instantiate a Rectangle object using w, h, x and y. Rectangle r = new Rectangle (x,y,w,h); X System.out.print("Perimiter System.out.print(r.getwidth()); System.out.print(r.getHeight()); System.out.print(r.getX()); System.out.print(r.getY()); = "); } // Calculate and output the perimeter using Rectangle class methods. 29 30 31 public void Setlocation (int x, int y){ 75% (32:1) codio@sierradialog-limbomatch:~/workspace$ | Guide Collapse Unit 2 - Using Objects -> Topics 2.3, 2.4 and 2.5- Methods 2.3.1 RectangleFun Write a program to enable the user to enter the width, height, and the coordinates for the location of a rectangle. This code is provided. Using the input values, construct a new Rectangle object. Calculate and output the perimeter of the rectangle using Rectangle class methods. Change the location of the rectangle to be 4 units to the left and 2 units up, and then print the new location. You must use the Rectangle methods setLocation, getX, and getY with the values 4 and 2 to do this in a calculation. The prompts and the labels for the output should appear exactly like those shown in the sample run shown below. Use method calls for all calculations and output. DO NOT input new values for these required adjustments, rather make the changes in the program using the methods belonging to the object. The signatures for these methods are as follows: public Rectangle(int x, int y,int width, int height) public double getWidth() public double getHeight() public double getX() public double getY() !!! RectangleFu... X 16 .out.print("Y: "); 17 = kb. nextInt (); 18 19 tantiate a Rectangle object using w, h, x and y. 20 gler = new Rectangle (x,y,w,h); 21 22 .out.print("Perimiter 23 .out.print (r.getwidth()); 24 .out.print(r.getHeight()); 25 . out.print(r.getX()); 26 .out.print(r.getY()); 27 28 29 Terminal culate and output the perimeter using Rectangle class methods. 30 31 d Setlocation (int x, int y) { 32 33 34 35 36 37 38 39 40 41 42 43 = nt the new location. _"'); e the rectangle 2 units up and 4 units to the left using a Rectangle class method. 75% (32:1) .out.print("New location is "); X codio@sierradialog-limbomatch:~/workspace$ Guide X Collapse Unit 2 - Using Objects -> Topics 2.3, 2.4 and 2.5-Methods 2.3.1 RectangleFun public double getX() public double getY() public void setLocation (int x, int y) Sample Run: COMPILE AND RUN Width: 5 Height: 2 X: 3 Y: -5 Perimeter = 14.0 New location is (-1.0,-3.0) First Compile and Run to make sure your program works, debug, edit and repeat if necessary, and then finally click Check It! when ready to submit to the autograder. Once it shows all tests passed, click on Mark as Completed to finish. Check It! !!!
Step by Step Solution
★★★★★
3.45 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
import javautilScanner import javaawtRectangle public class RectangleFun public static void mainStri...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