微风塘塘 2018-10-17 11:03 采纳率: 0%
浏览 2415
已采纳

eclipse无错误,java文件找不到或无法载入主要类,求大佬指点

代码如下

package CheckCarWeight;

interface ComputerWeight {
public double computeWeight();
}
class Television implements ComputerWeight {
public double computeWeight() {return 3.5; //重写computeWeight()方法
}
class Computer implements ComputerWeight {
public double computeWeight() {return 2.67; //重写computeWeight()方法
}

class WashMachine implements ComputerWeight {
public double computeWeight() {return 13.8; //重写computeWeight()方法
}
class Truck {
ComputerWeight [] goods;
double totalWeights=0;
Truck(ComputerWeight[] goods) {
this.goods=goods;
}
public void setGoods(ComputerWeight[] goods) {
this.goods=goods;
}
public double getTotalWeights() {
totalWeights=0;
for (int i=0;i<goods.length;i++) {totalWeights+=goods[i].computeWeight();} //计算totalWeights
return totalWeights;
}

}
public class CheckCarWeight {
public void main(String args[]) {
ComputerWeight[] goods=new ComputerWeight[650]; //650件货物
for(int i=0;i<goods.length;i++) { //简单分成三类
if(i%3==0)
goods[i]=new Television();
else if(i%3==1)
goods[i]=new Computer();
else if(i%3==2)
goods[i]=new WashMachine();
}
Truck truck=new Truck(goods);
System.out.printf("\n货车装载的货物重量:%-8.5f kg\n",truck.getTotalWeights());
goods=new ComputerWeight[68]; //68件货物
for(int i=0;i<goods.length;i++) { //简单分成两类
if(i%2==0)
goods[i]=new Television();
else
goods[i]=new WashMachine();
}
truck.setGoods(goods);
System.out.printf("货车装载的货物重量:%-8.5f kg\n",truck.getTotalWeights());
}
}}}}

  • 写回答

3条回答 默认 最新

  • 变速不变道 2018-10-17 12:57
    关注

    public void main(String args[]) ,这个main方法得是static的,写成这样 public static void main(String args[])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable