Points Possible 100 Use Rectangle.java and LengthWidthDemo.java Create new method in the Rectangle class called getArea
Posted: Thu Jul 14, 2022 2:06 pm
Points Possible 100 Use Rectangle.java and LengthWidthDemo.java Create new method in the Rectangle class called getArea to calculate the area of the rectangle. Call getArea method from the LengthWidthDemo class to print the area. LengthWidthDemo1.jpg Rectangle.java LengthWidthDemo.java
/t* Rectangle class, phase 3 Under constructionl public olass Rectangle र private double length; private double width; / * The setlength method stores a value in the length field. *param len The value to store in length. *
The setlength method stores a value in the length field. eparam len The value to store in length. public void setLength(double len) i length =1en; 7 The setwidth method stores a value in the width field. eparam w The value to store in width. y width = w; The getLength method returns a Rectang object's length. ereturn The value in the length field. public double getie \{ return length; * +1 public void setwidth(double w) f width = w; / object's length. *return The value in the length field. public double getlength() \{ return length; ) /** The getwidth method returns a Rectangle object's width. ereturn The value in the width field. public double getwidth() i return width;
This program demonstrates the Rectangle class' s setLength, setwidth, getLength, and getwidth methods. ∗/ // Call the object' // as an argument. box. setLength (10.0) I/ Call the object' /1 as an argument. box. setwidth (20.0); public class LengthWidthDemo public static void main(String[] args) I/ Create a Rectangle object. Rectangle box = new Rectangle(); // Call the object's setLength method, passing 10.0 I/ as an argument. box.setLength(10.0); I/ Call the object's setwidth method, passing 20.0 // as an argument. box.setWidth(20.0); // Display the object's length and width. System.out.println("The box's length is " + System. out. println( "The box's width is " + box.getWidth());
/t* Rectangle class, phase 3 Under constructionl public olass Rectangle र private double length; private double width; / * The setlength method stores a value in the length field. *param len The value to store in length. *
The setlength method stores a value in the length field. eparam len The value to store in length. public void setLength(double len) i length =1en; 7 The setwidth method stores a value in the width field. eparam w The value to store in width. y width = w; The getLength method returns a Rectang object's length. ereturn The value in the length field. public double getie \{ return length; * +1 public void setwidth(double w) f width = w; / object's length. *return The value in the length field. public double getlength() \{ return length; ) /** The getwidth method returns a Rectangle object's width. ereturn The value in the width field. public double getwidth() i return width;
This program demonstrates the Rectangle class' s setLength, setwidth, getLength, and getwidth methods. ∗/ // Call the object' // as an argument. box. setLength (10.0) I/ Call the object' /1 as an argument. box. setwidth (20.0); public class LengthWidthDemo public static void main(String[] args) I/ Create a Rectangle object. Rectangle box = new Rectangle(); // Call the object's setLength method, passing 10.0 I/ as an argument. box.setLength(10.0); I/ Call the object's setwidth method, passing 20.0 // as an argument. box.setWidth(20.0); // Display the object's length and width. System.out.println("The box's length is " + System. out. println( "The box's width is " + box.getWidth());