定义一个汽车类,要求该类中至少包含5个私有的属性(为每个属性定义设置和获取方法),该类中至少包含两个构造方法(一个无参,一个有参),以及包含5~6个方法来描述汽车对象的行为(其中一个方法要能打印输出

定义一个汽车类,要求该类中至少包含5个私有的属性(为每个属性定义设置和获取方法),该类中至少包含两个构造方法(一个无参,一个有参),以及包含5~6个方法来描述汽车对象的行为(其中一个方法要能打印输出汽车对象的所有属性值)。

上代码

package SencondDay;

import java.math.BigDecimal;


public class Car {
    private String name;
    private BigDecimal price;
    private String color;
    private Integer busload;
    private String weight;

    public Car(String name, BigDecimal price, String color, Integer busload, String weight) {
        this.name = name;
        this.price = price;
        this.color = color;
        this.busload = busload;
        this.weight = weight;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

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

    public String getColor() {
        return color;
    }

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

    public Integer getBusload() {
        return busload;
    }

    public void setBusload(Integer busload) {
        this.busload = busload;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public static void CarFly(){
        System.out.println("这车不能飞!");
    }
    public static void CarRun(){
        System.out.println("车跑不远了!");
    }
    public static void CarPrice(){
        System.out.println("这车太贵!");
    }
    public static void CarLife(){
        System.out.println("这车没几年寿命了!");
    }
    public static void CarPeople(){
        System.out.println("这车坐了3个人!");
    }
    public static void AllCar(){
        BigDecimal bigDecimal=new BigDecimal("15155");
        Car car=new Car("本田",bigDecimal,"red",3,"15521吨");
        System.out.println("汽车名: "+car.name);
        System.out.println("汽车价钱: "+bigDecimal);
        System.out.println("汽车颜色: "+car.color);
        System.out.println("汽车载客量: "+car.busload);
        System.out.println("汽车空载重量: "+car.weight);
    }


    public static void main(String[] args) {
       Car.AllCar();
    }
}




发布了69 篇原创文章 · 获赞 54 · 访问量 9575

猜你喜欢

转载自blog.csdn.net/kingtok/article/details/103064779