用java写一个封装类车系 厂商 车类 品牌 车型 级别 价格 时间 销量 销售规模(亿) 省份 城市
时间: 2023-12-22 10:03:43 浏览: 72
好的,我可以编写一个Java类来封装这些信息。以下是示例代码:
```java
public class Car {
private String series; // 车系
private String manufacturer; // 厂商
private String category; // 车类
private String brand; // 品牌
private String model; // 车型
private String level; // 级别
private double price; // 价格
private String year; // 时间
private int salesVolume; // 销量
private double salesScale; // 销售规模(亿)
private String province; // 省份
private String city; // 城市
// 构造方法
public Car(String series, String manufacturer, String category, String brand, String model, String level, double price, String year, int salesVolume, double salesScale, String province, String city) {
this.series = series;
this.manufacturer = manufacturer;
this.category = category;
this.brand = brand;
this.model = model;
this.level = level;
this.price = price;
this.year = year;
this.salesVolume = salesVolume;
this.salesScale = salesScale;
this.province = province;
this.city = city;
}
// getter 和 setter 方法
public String getSeries() {
return series;
}
public void setSeries(String series) {
this.series = series;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public int getSalesVolume() {
return salesVolume;
}
public void setSalesVolume(int salesVolume) {
this.salesVolume = salesVolume;
}
public double getSalesScale() {
return salesScale;
}
public void setSalesScale(double salesScale) {
this.salesScale = salesScale;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
// toString 方法
@Override
public String toString() {
return "Car{" +
"series='" + series + '\'' +
", manufacturer='" + manufacturer + '\'' +
", category='" + category + '\'' +
", brand='" + brand + '\'' +
", model='" + model + '\'' +
", level='" + level + '\'' +
", price=" + price +
", year='" + year + '\'' +
", salesVolume=" + salesVolume +
", salesScale=" + salesScale +
", province='" + province + '\'' +
", city='" + city + '\'' +
'}';
}
}
```
这个类有一些私有字段,它们代表车辆的各个属性,例如车系、厂商、车型等。类还包括一个构造方法,可以在创建对象时设置这些属性;以及一些 getter 和 setter 方法,用于获取和设置对象的属性。此外,还有一个toString方法,用于将对象转换为一个字符串表示。
阅读全文