首页 > 代码库 > 机动车
机动车
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)); }}
机动车
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。