Complete the implementation of the following program. You should
be able to figure out what's needed in each class based on the
driver program. (Write code in Test. java, Rectangle.java, and
Square.java)
Sample run
Input:
Output:
Given Code:
Test.java
import java.util.Scanner;
// your code starts here
// your code ends here
public class Test {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
// create a square
Shape sq = new Square(stdin.nextDouble());
System.out.println(sq.area());
System.out.println(((Rectangle)
sq).getLength());
((Rectangle)
sq).setLength(stdin.nextDouble());
System.out.println(sq.area());
System.out.println(((Rectangle)
sq).getLength());
}
}
Shape.java
package chapter9.shape;
public interface Shape {
double area();
}
Rectangle.java
package chapter9.shape;
public class Rectangle implements Shape {
// your code starts here
// your code ends here
}
Square.java
package chapter9.shape;
public class Square extends Rectangle {
public Square(double side) {
// your code starts here
// your code ends here
}
}
Complete the implementation of the following program. You should be able to figure out what's needed in each class based
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Complete the implementation of the following program. You should be able to figure out what's needed in each class based
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!