本人一java新手,碰到以下问题,请各为大侠不吝赐教,在这里先谢过了!
包文件:
package package1;
//接口 面积
interface shape_area
{
void area();
}
//抽象类 shape
abstract class shape
{
abstract void width();
}
//类 矩形
class rectangle extends shape implements shape_area
{
public double wid;
public double len;
rectangle(double x,double y)
{
wid=x;
len=y;
}
public void width()
{
System.out.println("The rectangle's area is "+(wid+len)*2);
}
public void area()
{
System.out.println("The rectangle's area is "+wid*len);
}
}
// 类 三角形
class triganle extends shape implements shape_area
{
double x,y,z;
triganle(double a,double b,double c)
{
x=a;
y=b;
z=c;
}
public void width()
{
System.out.println("The triangle's wid is "+(x+y+z));
}
public void area()
{
double d;
d=(x+y+z)/2;
System.out.println("The triangle's area is "+Math.sqrt(d*(d-x)*(d-y)*(d-z)));
}
}
//类 圆
class circle extends shape implements shape_area
{
double radius;
circle(double x)
{
radius=x;
}
public void area()
{
System.out.println("The area of the circle is "+3.14*radius*radius);
}
public void width()
{
System.out.println("The width of the circle is "+3.14*2*radius);
}
}
//类 四边型
class polygon extends shape implements shape_area
{
double m,n,p,q;//四条边的长度
double x;
polygon(double a,double b,double c,double d,double e)
{
m=a;n=b;p=c;q=d;x=e;
}
public void area()
{
double d,sum=0;
d=(m+n+x)/2;
sum+=Math.sqrt(d*(d-m)*(d-n)*(d-x));
d=(p+q+x)/2;
sum+=Math.sqrt(d*(d-p)*(d-q)*(d-x));
System.out.println("The area of the polygon is "+sum);
}
public void width()
{
System.out.println("The width of the polygon is "+m+n+q+p);
}
}
使用包的文件:
import package1.*;
class graphshape
{
public static void main(String args[])
{
rectangle rec1=new rectangle(2.0,3.0);
rec1.area();
circle cir1=new circle(2.0);
cir1.area();
triganle tri1=new triganle(3.0,4.0,5.0);
tri1.width();
polygon pol1=new polygon(5,6,7,8,9);
pol1.area();
pol1.width();
}
}
错误:
The type rectangle is not visible
The type circle is not visible
The type triganle is not visible
The type polygon is not visible