package dx; public class Car { //构造类
public Car()
{
System.out.println("Car的构造类");
} //构造类重用,初始化空车重量
public Car(double KongChe)
{
kongche = KongChe;
} //成员变量 double kongche; //成员方法,计算货物重量
public double shizhong(double manzai)
{ return manzai - kongche; } //方法重载 含水量高的货物输入含水率 public double shizhong(double manzai,double hanshuilv)
{ return manzai * (1- hanshuilv) - kongche; }
}
package dx; public class Yuanliao { public static void main(String[] args) { double kuangshi = 20;//需要的矿石原料量
double mei = 10;//需要的煤量 double ks = 0;//当前矿石量
double m = 0;//当前煤量
double hsl = 0.01;//含水率 double kc = 1.5;//空车重量 double arr[][] = {{1,6},{2,5},{9,7},{8,6},{6,6}};//创建车号,总重数组 //实例化Car对象
Car car = new Car(kc); for(int i = 0; i < arr.length; i++)
{
//车号
int n = (int)arr[i][0]; //总重
double zz = arr[i][1]; //车号小于等于5的装载矿石,大于5装载煤
if(n <= 5)
{
//调用car方法计算净重
double jz = car.shizhong(zz); ks = ks + jz; }
else
{
//重用car方法计算净重
double jz = car.shizhong(zz , hsl); m = m + jz;
}
} //判断矿石是否已足够
if(ks >= kuangshi)
{
System.out.println("矿石已足够");
}
else
{
System.out.println("矿石不足");
} //判断煤是否已足够
if(m >= mei)
{
System.out.println("原料煤已足够");
}
else
{
System.out.println("原料煤不足");
} } }