RectangleFu... X 1 2 import java.awt. Rectangle; W N 3 import java.util.Scanner; 4 5 public class...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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! !!! 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! !!!
Expert Answer:
Answer rating: 100% (QA)
import javautilScanner import javaawtRectangle public class RectangleFun public static void mainStri... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Hazel has $100,000 in savings that she plans to use as a down payment on a house that costs $650,000. She selects an closed, fixed rate mortgage with a 3-year term, a 20 year amortization period and...
-
Welcome to week 5. This week we will be discussing an important topic, teacher evaluations. There has been a big push to count the teacher evaluation as a determining factor toward incentive pay...
-
A manufacturer purchases a part for use at both of its plants-one at Roseville, California, the other at Akron, Ohio. The part is available in limited quantities from two suppliers. Each supplier has...
-
Which description does NOT fit in description of "issues" in the context of international standards? a. An unsettled matter. b. A vital matter. c. A change in the environment. d. A concern or...
-
Assign the following molecules to point groups: (a) HF, (b) IF7 (pentagonal bipyramid), (c) XeO2F2, (see-saw), (d) Fe,(CO)9 (22), (e) Cubane, C8H8, (f) Tetrafluorocubane, C8H4F4 (23) cO Fe co 23
-
For the network of Fig. 7.96, determine: a. IDQ and VGSQ. b. VDS and VS. 18 V 2.2 k DSS = 8 mA 1 GS 0 0.39 k -4V
-
The Wide World of Fluids article "At 12,600 mpg It Doesn't Cost Much to 'Fill 'er Up,"'. (a) Determine the power it takes to overcome aerodynamic drag on a small \(\left(6 \mathrm{ft}^{2} ight.\)...
-
Tesford plc has estimated net cash flows from operations (after interest and taxation) for the next five years as follows: YearNet cash flows 1 ........................... 3,000,000 2...
-
Discuss the cultural differences between China and the United States. What would be the biggest adjustments I might need to make if working there as an expatriate? What are the most...
-
Shayla Green owns Creative Designs. The trial balance of the firm for January 31, 20X1, the first month of operations, is shown below. End-of-the-month adjustments must account for the following...
-
Renovations costing $70,000 are being considered for the HVAC system in a commercial building. Energy savings are expected to be $14,500 annually. The business earns 16% on its current investments....
-
3. In relation to the concept of a socket discuss the following: [15 marks] (i) What is the purpose of a socket? (5 marks) (ii) After creating a socket a server application modifies it to become a...
-
Purpose: Computer forensics professionals should understand the concept of chain of custody because evidence in court depends on it being properly handled. This assignment will emphasize the...
-
1. Explain, with the aid of a diagram, what happens to the money supply, money demand, the value of money, and the price level if the Central Bank increases the money supply.
-
Currently, the US seems poised to exit the Great Recession. Suppose that in the long run, the US economy will experience strong, sustained economic growth over the next decade. a. Using the loanable...
-
The following graph depicts the market for loanable funds. An investment tax credit effectively lowers the tax bill of any firm that purchases new capital in the relevant time period. Suppose the...
-
Part A What is the resistance of a Nichrome wire at 0.0 C if its resistance is 200.000 at 11.5 C? Express your answer using four significant figures. R = , , , 114.5 Submit Try Again R = I, , , T...
-
The following table shows the rates of total return in successive years from 2004 to 2008 for the Sprott Canadian Equity Fund and for the benchmark Toronto Stock Exchange S&P/TSX Composite Index. By...
-
a. Wilson filed his individual tax return on the original due date, but failed to pay $700 in taxes that were due with the return. If Wilson pays the taxes exactly 2 months late, calculate the amount...
-
Greg died on July 1, 2012, and left Lea, his wife, a $50,000 life insurance policy which she elects to receive at $5,000 per year plus interest for 10 years. In the current year, Lea receives $6,200....
-
Ken (age 31) and Amy (age 28) Booth have brought you the following information regarding their income, expenses, and withholding for the year. They are unsure which of these items must be used to...
-
What is the quick (acid test) ratio? A. 0.9 B. 4.8 C. 0.8 D. 0.2 E. 1.7 Using the following balance sheet and income statement Balance sheet m Property 200 Trade payables Plant and equipment 300 Tax...
-
What is the receivables holding period? A. 21.6 days. B. 8 times. C. 19.4 days. D. 4.7 times. E. 28.2 days. Using the following balance sheet and income statement Balance sheet m Property 200 Trade...
-
The most appropriate measure of profitability from the point of view of the shareholders is: A. Return on equity. B. Return on capital employed. C. Return on non-current assets. D. Profit on sales.
Study smarter with the SolutionInn App