Question: TI.IT LAB: Rectangular (interraces) Define an interface as follows: The Rectangular interface has two methods.getLength() and getWidth(). Both of these methods have no parameters and





TI.IT LAB": Rectangular (interraces) Define an interface as follows: The Rectangular interface has two methods.getLength() and getWidth(). Both of these methods have no parameters and return decimal numbers. Define the following classes which should implement the Rectangular interface: -The Rectangle class has two instance variables: length and width-The Square class has a single instance variable: length Since A Square is Rectangular and has all 4 sides the same length, it can implement getWidth() by returning the length of a side. Ex if the input is 4 5 the outputs Square with Length: The length is: 3.00 3.00 3.00 4.00 and width: Rectangle with Length: The ength is: The width is: 5.00 4.00 5.00 File is marked as read only Current file: Shape Driver.java 8 1 import java.util.Scanner; 2 3 public class ShapeDriver 4 public static void main(String[] args) { 5 Scanner scnr = new Scanner(System.in); 6 7 double rectLength, rectWidth; double sqLength; 9 10 SqLength = scnr.nextDouble(); 11 rectLength = scnr.nextDouble(); 12 rectWidth = scnr.nextDouble(); 13 14 15 16 17 18 19 20 21 22 23 24 25 } Rectangular rect = new Rectangle(rectLength, rectWidth); Rectangular square = new Square (sqlength); System.out.printf(" System.out.printf(" System.out.printf(" Square with length: %7.2f ", sqLength); The length is: %7.2f ", square.getLength()); The width is: %7.2f ", square.getWidth(); System.out.printf("Rectangle with length: %7.2f and width: %7.2f ", rectLength, rectWidth); System.out.printf(" The length is: %7.2f ", rect.getLength()); System.out.printf(" The width is: %7.2f ", rect.getWidth()); evelop mode Submit mode Run your program Search 1 // TODO: Create the Rectangular interface 2 ngular.java 3 4 // TODO: Create the getLength() method which takes no parameters, returns a decimal 5 6 7 // TODO: Create the getWidth() method which takes no parameters, returns a decimal 8 9 Current file: Square.java 1 // TODO: Square class implements Rectangular 2 3 4 // TODO: Declare private field: length 5 6 // TODO: Define constructor which takes parameter length // TODO: Create methods getLength() and getwidth() to fulfill the requirements of Rectangular op mode Submit modo // TODO: Rectangle class implements Rectangular Current file: Rectangle.java // TODO: Declare private fields: length and width 1/ TODO: Define constructor with parameters for length and width 11 TODO: Create methods getLegnth() and getWidth() to fulfill the requirements of Rectangu
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
