Java练习题求解

[复制链接]
查看11 | 回复1 | 2008-11-9 11:30:38 | 显示全部楼层 |阅读模式
2、根据课堂PPT上的图示的类的结构和给定代码框架TestShape,完成该下面的程序:
abstract class Shape {
protected int x, y, k;
protected double m;
abstract public double getPerimeter();
abstract public double getArea();
public void display(){
System.out.print("The perimeter="+getPerimeter()+"\t and the area="+getArea());
}
}
class Circle extends Shape{// 完成类的定义
Circle(int r){
// 写语句
}
public double getPerimeter(){
// 写语句
}
public double getArea(){
// 写语句
}
public void display(){
// 写语句
}
}
class Square extends Shape{
Square(int a, int b){
// 写语句
}
public double getPerimeter(){
// 写语句
}
public double getArea(){
// 写语句
}
public void display(){
System.out.println("矩形边长分别为"+x+"和"+y+":");
super.display();
System.out.println();System.out.println();
}
}
class Cubic extends Shape{
Cubic(int a, int b, int c){
// 写语句
}
public double getPerimeter(){
// 写语句
}
public double getArea(){
// 写语句
}
public double getVolume(){
// 写语句
}
public void display(){
System.out.println("立方体边长分别为"+x+"、"+y+"和"+k+":");
// 写语句
}
}
public class TestShapes {

public static void main(String[] args) {

/* 分别生成半径为3的园,-个边长分别为4和5的矩形,

以及三个边长为6、7、8的立方体,并显示出结果,格式如下:

园的半径是3:

The perimeter=X and the area=Y



矩形边长分别为4和5:

The perimeter=X and the area=Y



立方体边长分别为6、7和8:

The perimeter=X and the area=Yand the volume=Z

*/

// 写语句



}
}

回复

使用道具 举报

千问 | 2008-11-9 11:30:38 | 显示全部楼层
abstract class Shape { protected int x, y, k; protected double m; abstract public double getPerimeter(); abstract public double getArea(); public void display() {System.out.println("The perimeter=" + getPerimeter() + "\t and the area="
+ getArea()); }}class Circle extends Shape { // 完成类的定义 Circ...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行