我刚才找到了一个程序,有了大概的了解了!我也给大家看一下!
import javax.swing.JOptionPane;
class Rectangle extends Shape
{
public double mianji(double c,double k)
{
return c * k;
}
}
class Square extends Shape
{
public double mianji(double c,double k)
{
return c * k;
}
}
class Circle extends Shape
{
public double mianji(double y,double P)
{
return P * y * P * y;
}
}
abstract class Shape
{
public abstract double mianji(double x,double y);
}
public class jj
{
public static void main(String[] dafdasdf)
{
final double P = 3.14;
System.out.println("输入长");
double c = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));
System.out.println("输入宽");
double k = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));
System.out.println("输入输入半径");
double y = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Number"));
Rectangle a = new Rectangle();
double cf1 = a.mianji(c,k);
System.out.println("长方形的面积为:"+cf1);
Square b = new Square();
double zf1 = b.mianji(c,k);
System.out.println("正方形的面积为:"+zf1);
Circle d = new Circle();
double yy1 = d.mianji(y,P);
System.out.println("圆形的面积为:"+yy1);
}
}