vehicle.java
来自「java(sl275课程习题解module1-module3共7道习题的题目以及」· Java 代码 · 共 38 行
JAVA
38 行
public class Vehicle
{
private double load,maxLoad;
public Vehicle(double maxLoad)
{
this.maxLoad=kiloToNewts(maxLoad);
}
public double getLoad()
{
return newtsToKilo(load);
}
public double getMaxLoad()
{
return newtsToKilo(this.maxLoad);
}
public boolean addBox(double weight)
{
boolean f;
if (this.load+kiloToNewts(weight)>this.maxLoad)
f=false;
else
{
f=true;
this.load=this.load+kiloToNewts(weight);
}
return f;
}
private double newtsToKilo(double weight)
{
return (weight*9.8);
}
private double kiloToNewts(double weight)
{
return (weight/9.8);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?