package com.hanqi.test;
public class jidongche {
private String chepaihao;//車牌號
private int speed;//速度
private double weight;//載重量
//無參構造方法
jidongche()
{
}
public String getChepaihao() {
return chepaihao;
}
public void setChepaihao(String chepaihao) {
this.chepaihao = chepaihao;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
//有參構造方法
jidongche(String cph,int sp,double wh)
{
chepaihao=cph;
speed=sp;
weight=wh;
}
//設置成員方法
public int getAddspeed(int add)
{
return speed+=add;
}
public int getjianspeed(int jian)
{
return speed-=jian;
}
public void setchepaihap(String chage)
{
chepaihao=chage;
}
jidongche jdc=new jidongche();
jdc.setChepaihao("xx1234");
jdc.setSpeed(100);
jdc.setWeight(100);
System.out.println("無參構造方法車牌號為:"+jdc.getChepaihao()+"\r速度為:"+jdc.getSpeed()+"\r載重量為:"+jdc.getWeight());
jdc.setChepaihao("遼A9752");
jdc.getAddspeed(30);
System.out.println("無參構造方法將車牌號改為:"+jdc.getChepaihao()+"\r速度增加到:"+jdc.getSpeed());
jidongche jdc1=new jidongche("xx1234", 150, 100);
jdc1.getjianspeed(30);
jdc1.setchepaihap("遼B5086");
System.out.println("有參構造方法將車牌號改為:"+jdc1.getChepaihao()+"\r速度減為:"+jdc1.getSpeed());
System.out.println("該車輛的載重量為:"+jdc1.getWeight());
