-->
当前位置:首页 > 题库 > 正文内容

编程题:Abstract and Shape

Luz2年前 (2022-11-12)题库456
We have abstract class Shape which has abstract method getArea, class Circle and Rectangle will inherit from Shape.Please read and finish code as follow:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int radius = input.nextInt();
int height = input.nextInt();
int width = input.nextInt();
//to create an Shape Array whose length is 2
Shape[] shapes =【】;
//shapes[0] refer to a Circle object
shapes[0] =【】;
//shapes[1] refer to a Rectangle object
shapes[1] = 【】;
//call getArea method with shapes
for(int i =0;i<shapes.length;i++)
System.out.printf("the area of shape :%.2f\n",【】);
}

}
//to declare abstract class
【】 Shape{
//to declare abstract method double getArea();
【】


}
class Circle 【】{
private int radius;
//override method getArea
【】
public Circle(int radius) {
super();
this.radius = radius;
}
}
class Rectangle 【】{
private int height,width;

//override method getArea
【】


public Rectangle(int height, int width) {
super();
this.height = height;
this.width = width;
}
}







请在这里写题目描述。例如:本题目要求读入2个整数A和B,然后输出它们的和。

### 输入格式:

input radius , height and width at a line.

### 输出格式:

output the area of circle and rectangle object at different lines.

### 输入样例:

在这里给出一组输入。例如:

in
4 5 6


### 输出样例:

在这里给出相应的输出。例如:

out
the area of shape :50.27
the area of shape :30.00







答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。