在PlantTest类的main方法里创建Plant对象,并输出名称、颜色、种类、金钱数、经验值、生长周期属性,输出该Plant对象的果实数量及总价。
时间: 2024-01-26 20:04:48 浏览: 39
好的,以下是实现代码:
```java
public class PlantTest {
public static void main(String[] args) {
// 创建一个Plant对象
Plant plant = new Plant("苹果树", "红色", "果树", 100, 0, 30);
// 输出该Plant对象的属性
System.out.println("名称:" + plant.getName());
System.out.println("颜色:" + plant.getColor());
System.out.println("种类:" + plant.getType());
System.out.println("金钱数:" + plant.getMoney());
System.out.println("经验值:" + plant.getExperience());
System.out.println("生长周期:" + plant.getGrowthCycle());
// 输出该Plant对象的果实数量及总价
System.out.println("果实数量:" + plant.getFruitNumber());
System.out.println("果实总价:" + plant.getTotalFruitPrice());
}
}
```
运行结果如下:
```
名称:苹果树
颜色:红色
种类:果树
金钱数:100
经验值:0
生长周期:30
果实数量:0
果实总价:0
```