java技术支持--车类

问题:

 设计一个车辆类Vehicle,该Vehicle类具有属性:
车辆型号(vehId),用途(vehUse),性能(author),油耗(oil),颜色(color),价钱(price)。
要求属性私有,生成其共有的get/set 方法.
具有方法:show():该方法内显示该车的的详细信息
具有方法:start(),stop();
在创建一个Vehicle对象的同时给该对象各属性赋初值。(带参构造)
编写测试类TestVehicle,实现创建一个Vehicle对象Vehicle,打印出该车的详细信息。

Vehicle.java

public class Vehicle {

    public Vehicle(String vehId, String vehUse, String author, double oil, String color, double price) {
        this.vehId = vehId;
        this.vehUse = vehUse;
        this.author = author;
        this.oil = oil;
        this.color = color;
        this.price = price;
    }
    
    private String vehId;
    private String vehUse;
    private String author;
    private double oil;
    private String color;
    private double price;
    public void setAuthor(String author) {
        this.author = author;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void setOil(double oil) {
        this.oil = oil;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void setVehId(String vehId) {
        this.vehId = vehId;
    }

    public void setVehUse(String vehUse) {
        this.vehUse = vehUse;
    }

    public String getAuthor() {
        return author;
    }

    public String getColor() {
        return color;
    }

    public double getOil() {
        return oil;
    }

    public double getPrice() {
        return price;
    }

    public String getVehId() {
        return vehId;
    }

    public String getVehUse() {
        return vehUse;
    }
    void show(){
    System.out.println("the vehId is: "+vehId);
    System.out.println("the vehUse is: "+vehUse);
    System.out.println("the author is: "+author);
    System.out.println("the oil is: "+oil);
    System.out.println("the color is: "+color);
    System.out.println("the price is: "+price);
    }
    void start(){
        System.out.println("the car is going...");
    }
        void stop(){
            System.out.println("the car is stop...");
        }   
}

Test.java

public class Test {
  public static void main(String[]args){
             Vehicle vehicle=new Vehicle("tasla","travel","good",0,"black",10000);
       vehicle.show();
       vehicle.start();
       vehicle.stop();;
  }
}

运行结果:





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早日退休过上不劳而获生活

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值