11.按要求编写Java应用程序。 (1)创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)、减速(车速自减)、修改车牌号,查询车的...

package java1;

public class Che {

        //属性

        public String nub;
        public int speed;
        public double weight ;
        
        
        Che()
        {
            nub="XX1234";
            speed=100;
            weight=100;
        }

        Che(String nub, int speed,double weight) 
        {
            this.nub = nub;
            this.speed = speed;
            this.weight = weight;
        }
        public int add(int add)
        {
            System.out.println("车速增加"+add+"当前车速为:"+(speed+add));
            return speed;
        }
        public int jian(int jian)
        {
            System.out.println("车速减"+jian+"当前车速为:"+(speed-jian));
            return speed;
        }
        public String setNub(String nub)
        {
            this.nub=nub;
            System.out.println("当前车牌为"+nub);
            return nub;
        }
        public double setWeight(double weight)
        {
            this.weight=weight;
            System.out.println("当前载重"+weight);
            return weight;
        }
        
}


        Che che1=new Che();
        che1.setNub("辽B5086");
        che1.add(20);
        System.out.println("车牌为:"+che1.nub+",车速为:"+che1.speed+",载重为"+che1.weight);
        
        Che che2=new Che("辽B5086",150,200);
        che2.jian(20);
        System.out.println("车牌为:"+che2.nub+",车速为:"+che2.speed+",载重为"+che2.weight);

当前车牌为辽B5086
车速增加20当前车速为:120
车牌为:辽B5086,车速为:100,载重为100.0
车速减20当前车速为:130
车牌为:辽B5086,车速为:150,载重为200.0

转载于:https://www.cnblogs.com/zs6666/p/5887183.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值