import java.io.*;
public abstract class TuXing
{
public double a;
public void setA(double i)
{
a=i;
}
public abstract double area();
}
public class ZhengFangXing extends TuXing
{
public double area()
{
return a*a;
}
}
public class ChangFangXing extends TuXing
{
public double b;
public void setB(double i)
{
b=i;
}
public double area()
{
return a*b;
}
}
public class SanJiaoXing extends TuXing
{
public double b;
public double c;
public void setB(double i)
{
b=i;
}
public void setC(double j)
{
c=j;
}
public double area()
{
double p=(a+b+c)/2.0;
return Math.sqrt(p*(p-a)*(p-b)*(p-c));
}
}
public class Test11
{
public static void main(String args[])
{
ZhengFangXing zheng=new ZhengFangXing();
ChangFangXing chang=new ChangFangXing();
SanJiaoXing san=new SanJiaoXing();
if(args.length==0)
{
System.out.println("你在命令行中没有输入参数!");
// System.exit();
}
if(args.length==1)
{
zheng.setA(Double.parseDouble(args[0]));
System.out.println("正方形的面积是:"+zheng.area());
}
if(args.length==2)
{
chang.setA(Double.parseDouble(args[0]));
chang.setB(Double.parseDouble(args[1]));
System.out.println("长方形的面积是:"+chang.area());
}
if(args.length>=3)
{
san.setA(Double.parseDouble(args[0]));
san.setB(Double.parseDouble(args[1]));
san.setC(Double.parseDouble(args[2]));
System.out.println("三角形的面积是:"+san.area());
}
}
}
编译后怎么有这样的错误啊?
C:\>javac Test11.java
Test11.java:2: 类 TuXing 是公共的,应在名为 TuXing.java 的文件中声明
public abstract class TuXing
^
Test11.java:11: 类 ZhengFangXing 是公共的,应在名为 ZhengFangXing.java 的文件中
声明
public class ZhengFangXing extends TuXing
^
Test11.java:18: 类 ChangFangXing 是公共的,应在名为 ChangFangXing.java 的文件中
声明
public class ChangFangXing extends TuXing
^
Test11.java:30: 类 SanJiaoXing 是公共的,应在名为 SanJiaoXing.java 的文件中声明
public class SanJiaoXing extends TuXing
^
4 错误
然后我改成:
import java.io.*;
abstract class TuXing
{
public double a;
public void setA(double i)
{
a=i;
}
public abstract double area();
}
class ZhengFangXing extends TuXing
{
public double area()
{
return a*a;
}
}
class ChangFangXing extends TuXing
{
public double b;
public void setB(double i)
{
b=i;
}
public double area()
{
return a*b;
}
}
class SanJiaoXing extends TuXing
{
public double b;
public double c;
public void setB(double i)
{
b=i;
}
public void setC(double j)
{
c=j;
}
public double area()
{
double p=(a+b+c)/2.0;
return Math.sqrt(p*(p-a)*(p-b)*(p-c));
}
}
public class Test11
{
public static void main(String args[])
{
ZhengFangXing zheng=new ZhengFangXing();
ChangFangXing chang=new ChangFangXing();
SanJiaoXing san=new SanJiaoXing();
if(args.length==0)
{
System.out.println("你在命令行中没有输入参数!");
// System.exit();
}
if(args.length==1)
{
zheng.setA(Double.parseDouble(args[0]));
System.out.println("正方形的面积是:"+zheng.area());
}
if(args.length==2)
{
chang.setA(Double.parseDouble(args[0]));
chang.setB(Double.parseDouble(args[1]));
System.out.println("长方形的面积是:"+chang.area());
}
if(args.length>=3)
{
san.setA(Double.parseDouble(args[0]));
san.setB(Double.parseDouble(args[1]));
san.setC(Double.parseDouble(args[2]));
System.out.println("三角形的面积是:"+san.area());
}
}
}
(把前面的几个public去了后就行了)
乍啦?
可能是很低级的问题吧?