package a;
public class Jidongche {
private String chepaihao;
private int chesu;
private double zaizhong;
public String getChepaihao() {
return chepaihao;
}
public void setChepaihao(String chepaihao) {
this.chepaihao = chepaihao;
}
public int getChesu() {
return chesu;
}
public void setChesu(int chesu) {
this.chesu = chesu;
}
public double getZaizhong() {
return zaizhong;
}
public void setZaizhong(double zaizhong) {
this.zaizhong = zaizhong;
}
public Jidongche()
{
chepaihao="XX231";
chesu=100;
zaizhong=100;
}
public Jidongche(String chepaihao, int chesu, double zaizhong) {
super();
this.chepaihao = chepaihao;
this.chesu = chesu;
this.zaizhong = zaizhong;
}
public void jiasu(int sudu)
{
if(sudu<0)
{
System.out.println("无法加速");
}
else
{
chesu+=sudu;
}
}
public void jiansu(int sudu)
{
if(sudu<0)
{
System.out.println("无法减速");
}
else
{
if((chesu-sudu)<0)
{
System.out.println("减速失败");
}
else
{
chesu-=sudu;
}
}
}
}
package a;
public class Che {
public static void main(String[] args) {
Jidongche che1=new Jidongche();
che1.setChepaihao("辽A9752");
che1.jiasu(30);
System.out.println("车牌号="+che1.getChepaihao());
System.out.println("当前车速="+che1.getChesu());
System.out.println("载重="+che1.getZaizhong());
Jidongche che2=new Jidongche("辽B5086",150,200);
che2.jiansu(20);
System.out.println("车牌号="+che2.getChepaihao());
System.out.println("当前车速="+che2.getChesu());
System.out.println("载重="+che2.getZaizhong());
}
}