用Java写一个记录物品信息的类
时间: 2023-11-13 17:03:51 浏览: 27
好的,以下是一个简单的Java类,用于记录物品信息:
```java
public class Item {
private String name;
private int quantity;
private double price;
public Item(String name, int quantity, double price) {
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
```
这个类有三个属性(name,quantity,price),用于存储物品的名称,数量和价格。还有一个构造函数,用于初始化这些属性。同时,这个类也包括了一些getter和setter方法,用于获取和设置这些属性的值。