声明三角形类,继承图形抽象类,计算三角形的面积和周长public abstract class closedFigure
{
protected String shape;
protected closedFigure(String shape)
{this.shape=shape;
}protected closedFigure()
{this("未知");
}
public abstract double area();
public abstract double perimeter();
public void print()
{System.out.println("一个"+this.shape+","+this.toString()+",周长为"+this.perimeter()+",面积为"+this.area());
}
}
public class Sjx extends closedFigure
{protected double a;
protected double b;
protected double c;
public Sjx(double a,double b,double c)
{super("三角形");
this.a=a;
this.b=b;
this.c=c;
}
public Sjx()
{this(0,0,0);
}public String toString()
{return "a边长"+this.a+",b边长"+this.b+",c边长"+this.c;
}
public double area()
{return (sqrt ((a+b+c)/2.0)* (((a+b+c)/2.0)-a) *(((a+b+c)/2.0)-b)*(((a+b+c)/2.0)-c));
}
public double perimeter()
{
return (a+b+c);
}
}
怎么在jdk中编译,而且他告诉我有两处错误。
{
protected String shape;
protected closedFigure(String shape)
{this.shape=shape;
}protected closedFigure()
{this("未知");
}
public abstract double area();
public abstract double perimeter();
public void print()
{System.out.println("一个"+this.shape+","+this.toString()+",周长为"+this.perimeter()+",面积为"+this.area());
}
}
public class Sjx extends closedFigure
{protected double a;
protected double b;
protected double c;
public Sjx(double a,double b,double c)
{super("三角形");
this.a=a;
this.b=b;
this.c=c;
}
public Sjx()
{this(0,0,0);
}public String toString()
{return "a边长"+this.a+",b边长"+this.b+",c边长"+this.c;
}
public double area()
{return (sqrt ((a+b+c)/2.0)* (((a+b+c)/2.0)-a) *(((a+b+c)/2.0)-b)*(((a+b+c)/2.0)-c));
}
public double perimeter()
{
return (a+b+c);
}
}
怎么在jdk中编译,而且他告诉我有两处错误。
解决方案 »
- 从Oracle中读取的NUMBER类型一般在java中用什么型
- 关于java.io类的,谁能先解释清楚原因就给分
- 一个java连接数据库的问题
- 怎么在JAVA中调用VC++ OCX控件?(100分)
- 怎么把"134754481"里面都是半角的字符转成全角的字符串"134754481"??
- 通缉黑桃A : JBuilder 2005
- 请给我解释一下什么是“多态性”,最好举个例子,如何使用!
- 用Jbuilder3 遇到问题不能运行把可疑代码注掉后可以运行但是重新使用可疑代码时又可以运行了多次重复都是如此
- 难道weblogic6.0的性能真的是如此之烂??
- java 实例变量存放在堆区还是栈区?
- 求俄罗斯反方块代码
- 为什么可以对父类中private修饰的方法进行重写?
2处错误是:
1、一个java文件中,最多只能有一个类(或接口)用public修饰,并且该类(或接口)的名称
和文件名相同,故将public abstract class closeFigure中的public去掉;
2、sqrt不能直接拿来用,改为Math.sqrt()就行了。PS:类/接口的名称首字母要大写!
2处错误是:
1、一个java文件中,最多只能有一个类(或接口)用public修饰,并且该类(或接口)的名称
和文件名相同,故将public abstract class closeFigure中的public去掉;
2、sqrt不能直接拿来用,改为Math.sqrt()就行了。PS:类/接口的名称首字母要大写!
2 Sjx这种类名怎么看怎么疼 Triangle不行吗?
1、同一个文件最多只能有一个public修饰的类,所以把closeFigure、Sjx中的一个public去掉
2、换行的时候,一个字符串被拆分成多个字符串,字符串两端要用双引号包住,字符串之间要用+号连接,也就是说:
public void print()
{System.out.println("一个"+this.shape+","+this.toString()+",周长为"+this.perimeter()+",面积为"+this.area());
}
应该改成:
public void print()
{System.out.println("一个"+this.shape+","+this.toString()+",周长为"+this.perimeter()+",面积"+"为"+this.area());
}总体来说,你的代码比较让人蛋疼,下面给个稍微让人淡定一点的,供参考import java.util.*; abstract class Figure
{
protected String shape; protected Figure(String shape)
{
this.shape = shape;
} protected Figure()
{
this("未知");
} public abstract double area(); public abstract double perimeter(); public void print()
{
System.out.println("一个" + this.shape + "," + this.toString() + ",周长为"
+ this.perimeter() + ",面积为" + this.area());
}
}class Triangle extends Figure
{
protected double a;
protected double b;
protected double c; public Triangle(double a, double b, double c)
{
super("三角形");
this.a = a;
this.b = b;
this.c = c;
} public void print()
{System.out.println("一个"+this.shape+","+this.toString()+",周长为"+this.perimeter()+",面积" +"为"+this.area());
} public Triangle()
{
this(0, 0, 0);
} public String toString()
{
return "a边长" + this.a + ",b边长" + this.b + ",c边长" + this.c;
} public double area()
{
return (Math.sqrt((a + b + c) / 2.0) * (((a + b + c) / 2.0) - a)
* (((a + b + c) / 2.0) - b) * (((a + b + c) / 2.0) - c));
} public double perimeter()
{
return (a + b + c);
}
}
{
protected String shape; protected Figure(String shape)
{
this.shape = shape;
} protected Figure()
{
this("未知");
} public abstract double area(); public abstract double perimeter(); public void print()
{
System.out.println("一个" + this.shape + "," + this.toString() + ",周长为"
+ this.perimeter() + ",面积为" + this.area());
}
}class Triangle extends Figure
{
protected double a;
protected double b;
protected double c; public Triangle(double a, double b, double c)
{
super("三角形");
this.a = a;
this.b = b;
this.c = c;
} public Triangle()
{
this(0, 0, 0);
} public String toString()
{
return "a边长" + this.a + ",b边长" + this.b + ",c边长" + this.c;
} public double area()
{
return (Math.sqrt((a + b + c) / 2.0) * (((a + b + c) / 2.0) - a)
* (((a + b + c) / 2.0) - b) * (((a + b + c) / 2.0) - c));
} public double perimeter()
{
return (a + b + c);
}
}
http://007ej.com/user.asp
http://happyran.zbpifa.com