java这段程序,帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/09/21 14:51:48
public interface Graphic {
double getCircumference(); // 求周长
double getAreaSize(); // 求面积
}

/**
* 矩形类实现图形类
*/
public class Rectangular implements Graphic {
public static void main(String[] args){
private double width=5;
private double height=6;
public Rectangular(double width, double height) {
this.width = width;
this.height = height;
}
public double getAreaSize() {
return 2 * (width + height);
System.out.println(getAreaSize());
}
public double getCircumference() {
return width * height;
System.out.println(getCircumference());
}
}
}
之前没有public static void main(String[] args){ 听别人说缺少main函数,改了之后问题更多了,帮忙改下。还有一个问题,我想随便写出两个数字,比如我输入命令 java test 9 5。 9,5这两个值怎么能付给变量啊,做好说明下,最好把程序从头写下,谢谢

main函数和其他函数是并列的吧,你把所有函数写着main里面。这也太……不小心了。

public class Rectangular implements Graphic {
private double width=5;
private double height=6;
public Rectangular(double width, double height) {
this.width = width;
this.height = height;
}
public double getAreaSize() {
return 2 * (width + height);
}
public double getCircumference() {
return width * height;
}
public static void main(String[] args){
//把你要做的写在这里……
}
}

你的9,5就是存放在main函数的形参args中的。你在main中用args[0]就是“9”,args[1] 就是"5"

感觉这里就是一个矩形类,好像也没有理由把main函数写这里吧,当然为了测试这个类就另当别论了。

interface Graphic {

/**
* 求周长
*/
double getCircumference();

/**
* 求面积
*/
double getAreaSize();
}

/**
* 矩形类实现图形类
*/
class Rectangular implements Graphic {

/**
* 宽
*/
private doub