机动车

package com.homework.che;

public class Jidongche
{
    public String chepaihao;
    public int speed;
    public double zaizhong;
    
    Jidongche()
    {
        chepaihao="XX1234";
        speed=100;
        zaizhong=100;
    }
    Jidongche(String cph, int sp, double zz)
    {
        chepaihao=cph;
        speed=sp;
        zaizhong=zz;
    }
    
    public int addSpeed(int sd)
    {
        speed+=sd;
        return speed;
    }
    public int downSpeed(int sd)
    {
           speed-=sd;
           return speed;   
    }
    public String xiugai(String chepaihao)
    {
        this.chepaihao=chepaihao;
        return chepaihao;
    }
    public double zaizh(double zaizhong)
    {
        this.zaizhong=zaizhong;
        return zaizhong;
    }
package com.homework.che;

public class Text_jidongche 
{

    public static void main(String[] args)
    {
        Jidongche jidongche1=new Jidongche();
        System.out.println("机动车1,车牌号:"+jidongche1.chepaihao+"   车速:"+jidongche1.speed+"km/h   载重:"+jidongche1.zaizhong+"吨");
        System.out.println("修改车牌号为:"+jidongche1.xiugai("辽A9752"));
        System.out.println("加速20,此时速度为:"+jidongche1.addSpeed(20)+"km/h");
        
        
        Jidongche jidongche2=new Jidongche("辽B5086",150,200);
        System.out.println("机动车2,车牌号:"+jidongche2.chepaihao+"   车速:"+jidongche2.speed+"km/h   载重:"+jidongche2.zaizhong+"吨");
        System.out.println("减速30,此时速度为:"+jidongche2.downSpeed(30)+"km/h");
        
    }

}

 

posted @ 2016-09-20 10:09  庚庚庚庚庚辰  阅读(170)  评论(0编辑  收藏  举报