2、写一个面包类,类中有属性:品牌,生产日期,生产厂家; (一)有返回,无参数的方法: 得到面包的品牌方法,要求返回当前面包的品牌。 得到面包的生产日期的方法,要求返回当前面包的生产日期。 得到面包的生产厂家的方法,要求返回当前面包的生产厂家。 返回当前对象信息的方法,即toString()方法。 (二)无返回,有参数的方法: 设置当前面包的品牌方法,要求传入面包的新品牌,修改当前品牌。 设置当前面包的生产日期方法,要求传入面包的生产日期,修改当前生产日期。 设置当前面包的生产厂家方法,要求传入面包的生产厂家,修改当前生产厂家。
时间: 2023-05-29 09:05:47 浏览: 38
class Bread {
private String brand;
private String productionDate;
private String manufacturer;
// 有返回,无参数的方法
public String getBrand() {
return brand;
}
public String getProductionDate() {
return productionDate;
}
public String getManufacturer() {
return manufacturer;
}
public String toString() {
return "Brand: " + brand + "\n"
+ "Production Date: " + productionDate + "\n"
+ "Manufacturer: " + manufacturer;
}
// 无返回,有参数的方法
public void setBrand(String newBrand) {
brand = newBrand;
}
public void setProductionDate(String newProductionDate) {
productionDate = newProductionDate;
}
public void setManufacturer(String newManufacturer) {
manufacturer = newManufacturer;
}
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)