本届最后思考题中我的代码
package com.form;
//Shape图形类
public abstract class Shape {
double length;
double width;
double radius;
public abstract void perimeter();
public abstract void area();
}
package com.form;
//Rectangle子类
public class Rectangle extends Shape {
@Override
public void perimeter() {
// TODO Auto-generated method stub
System.out.println("长方形的周长为:"+(length+width)*2);
}
@Override
public void area() {
// TODO Auto-generated method stub
System.out.println("长方形的面积为:"+length*width);
}
}
package com.form;
//circle子类
public class Circle extends Shape {
@Override
public void perimeter() {
// TODO Auto-generated method stub
System.out.println("圆的周长为:"+2*Math.PI*radius);
}
@Override
public void area() {
// TODO Auto-generated method stub
System.out.println("圆的面积为:"+Math.PI*radius*radius);
}
}
package com.form;
import java.util.Scanner;
public class Instant {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner put=new Scanner(System.in);
Shape rectangle=new Rectangle();
System.out.print("请输入长方形的长:");
rectangle.length=put.nextDouble();
System.out.print("请输入长方形的宽:");
rectangle.width=put.nextDouble();
rectangle.perimeter();
rectangle.area();
Shape circle=new Circle();
System.out.print("请输入圆的半径:");
circle.radius=put.nextDouble();
circle.perimeter();
circle.area();
}
}