标签:
package liu0919; public class Jidongche { private String number;//车牌 private int speed;//车速 private double load;//载重 private String xinxi; //无参 public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public double getLoad() { return load; } public void setLoad(double load) { this.load = load; } public double addSpeed(int sd) { speed+=sd; return speed; } public int downSpeed(int sd) { speed-=sd; return speed; } Jidongche() { number="XX1234"; speed=100; load=100; } Jidongche(String number,int speed,double load) { this.number=number; this.speed=speed; this.load=load; } //有参有返回值 void Xinxi(String n,int s,double l) { xinxi=n+s+l; System.out.println("机动车2的车牌号是:"+n+"车速:"+s+"载重:"+l); } }
package liu0919; public class Ceshi_jidongche { public static void main(String[] args) { Jidongche jd=new Jidongche (); jd.setNumber("XX1234"); System.out.println("车牌号是:"+jd.getNumber()); jd.setLoad(100); System.out.println("载重是:"+jd.getLoad()); jd.setSpeed(100); System.out.println("车速是:"+jd.getSpeed()); System.out.println("机动车1的车牌是:"+jd.getNumber()+"载重:"+jd.getLoad()+"车速:"+jd.getSpeed()); //调用无参数的构造方法 jd.setNumber("辽A9752"); System.out.println("修改车牌号是:"+jd.getNumber()); System.out.println("加速后为:"+jd.addSpeed(20)); //有参数的 Jidongche jd2=new Jidongche ("辽B5086", 150, 200); jd2.Xinxi("辽B5086", 150, 200); System.out.println("减速后为:"+jd2.downSpeed(20)); } }
标签:
原文地址:http://www.cnblogs.com/liuyanzeng/p/5886606.html