JAVA定义汽车销售管理类,属性可根据功能需要添加,实现如下功能: produceCar,生产汽车,也即构造出汽车对象,应写入Car.txt文件中,实现对汽车信息的保存 点击复制后,将打开C知道体验页listCar,查看汽车产品数据
时间: 2023-06-05 09:08:56 浏览: 93
汽车销售系统(JAVA)
3星 · 编辑精心推荐
可以回答这个问题。以下是Java定义汽车销售管理类的代码,实现了produceCar方法来保存汽车信息到Car.txt文件中:
```java
import java.io.FileWriter;
import java.io.IOException;
public class CarSalesManagement {
private String brand;
private String model;
private String color;
private int price;
public CarSalesManagement(String brand, String model, String color, int price) {
this.brand = brand;
this.model = model;
this.color = color;
this.price = price;
}
public void produceCar() {
String carInfo = "Brand: " + brand + "; Model: " + model + "; Color: " + color + "; Price: " + price;
try {
FileWriter writer = new FileWriter("Car.txt", true);
writer.write(carInfo + "\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
你可以调用produceCar方法来构造出汽车对象并保存到Car.txt文件中。
阅读全文