package zuoye8; public abstract class Shape { private double zhouchang ;
private double mianji ; public Shape(double zhouchang, double mianji) {
super();
this.zhouchang = zhouchang;
this.mianji = mianji; } public Shape() {
super();
}
//抽象一个周长方法
public double zhouchang ()
{
return zhouchang;} }
package zuoye8; public class Juxing extends Shape { private double c;
private double d; public Juxing( double c, double d) {
super();
this.c = c;
this.d = d; } @Override
public double zhouchang() {
double zhouchang ;
zhouchang =(c+d)*2;
return zhouchang ;
} }
package zuoye8; public class Sanjaio extends Shape {
//三角形三边属性
private double a;
private double b;
private double c; public Sanjaio( double a, double b, double c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
public Sanjaio() { } //周长 public void
zhouchang (double a,double b,double c)
{
if(a+b>c&&Math.abs(a-b)<c)//绝对值,保证是正整数
{
double zhouchang ;
System.out.println(zhouchang =a+b+c); }
else
{
System.out.println("这不是三角形"); } } }
package zuoye8; public class E { public static void main(String[] args) { Juxing j=new Juxing(3,4);
System.out.println("长=4,宽=3的矩形周长="+j.zhouchang()); Sanjaio s=new Sanjaio();
System.out.println( "边分别是3,4,5的三边形周长是:");
s.zhouchang(3, 4, 5); s.zhouchang(3,1,5); } }