Use Rectanglejava and LengthWidthDemojava 1. Create new method in the Rectangle class called setheight to tet the height. 2. Call setheight method from the LengthWidhDemo class to set the height to 5.0. 3. Create new method in the Rectangle class called getheight to sot the height. 4. Call gotHeight method from the LengthWidthDemo class to print the height. 5. Create new method in the Rectangle class called getVolume to calculate the volume of the rectangle prism. 6. Call getVolume method from the LengthWidthDemo class to print the volume. LengthWidthDemo2.jpg Rectangle.java LengthWidthDemo.java
/** Rectangle class, phase 3 Under construction! public class Rectangle private double length; private double width; /** The setlength method stores a value in the public double getlength() \& \& * puram leturn length; public void setlength (double len) \{ length = len; \}
The setlength method stores a value in the length field. eparam len The value to store in length. public void sotLength(double len) ₹ length = len; 3 The setwidth method stores a value in the width field. eparam w the value to store in vidth. public void setwidth(double w ) ई width =wi 1 The getlength method returns a Rectangle object ′s length. ereturn The value in the length fleld. - public double getLength() f return length; 1 f+a The getwidth method returns a Rectangle object's width. ereturn The value in the width field. −f public double getwidth() १ return widthi ) 1 esc
This program demonstrates the Rectangle class's setLength, setWidth, getLength, and getwidth methods. 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 1/ as an argument. box. setLength (10.0); // Call the object's setwidth method, passing 20.0 I/ as an argument. box. setWidth (20.0); // Display the object's length and width. System.out.println("The box's length is " + box. getLength()); System, out. println("The box's width is " + box. getwidth()); \} )
Use Rectanglejava and LengthWidthDemojava 1. Create new method in the Rectangle class called setheight to tet the height
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Use Rectanglejava and LengthWidthDemojava 1. Create new method in the Rectangle class called setheight to tet the height
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!