码迷,mamicode.com
首页 > 其他好文 > 详细

机动车

时间:2016-09-19 20:58:17      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!