qq_41249520
微风塘塘
2018-10-17 11:03
采纳率: 75%
浏览 2.3k
已采纳

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条回答 默认 最新

  • qq_31499975
    墨妖吻我 2018-10-17 12:57
    已采纳

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

    点赞 评论
  • qq_16127313
    爱码少年 2018-10-17 12:09

    举例:
    看下 properties -》java bulid Path
    图片说明

    是不是all 和 none,还不行的话,先移除再重建

    点赞 评论
  • u012976158
    强化脑细胞 2018-10-18 05:47

    public static void main(String args[]) 程序执行的入口

    点赞 评论

相关推荐