package java1; public class Che { //属性 public String nub;
public int speed;
public double weight ; Che()
{
nub="XX1234";
speed=100;
weight=100;
} Che(String nub, int speed,double weight)
{
this.nub = nub;
this.speed = speed;
this.weight = weight;
}
public int add(int add)
{
System.out.println("车速增加"+add+"当前车速为:"+(speed+add));
return speed;
}
public int jian(int jian)
{
System.out.println("车速减"+jian+"当前车速为:"+(speed-jian));
return speed;
}
public String setNub(String nub)
{
this.nub=nub;
System.out.println("当前车牌为"+nub);
return nub;
}
public double setWeight(double weight)
{
this.weight=weight;
System.out.println("当前载重"+weight);
return weight;
} } Che che1=new Che();
che1.setNub("辽B5086");
che1.add(20);
System.out.println("车牌为:"+che1.nub+",车速为:"+che1.speed+",载重为"+che1.weight); Che che2=new Che("辽B5086",150,200);
che2.jian(20);
System.out.println("车牌为:"+che2.nub+",车速为:"+che2.speed+",载重为"+che2.weight);
当前车牌为辽B5086
车速增加20当前车速为:120
车牌为:辽B5086,车速为:100,载重为100.0
车速减20当前车速为:130
车牌为:辽B5086,车速为:150,载重为200.0