Complete the implementation of the following program. You should be able to figure out what's needed in each class based

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
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

Post by answerhappygod »

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
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply