Flower类设计 创建一个花类:Flower类: (1)string name、String color、 double price的私有成员 (2)包含有参构造方法和无参构造方法 (3)成员方法public void printInfo() 裁判测试程序样例中展示的是测试类的相关Java代码,其中缺失了部分代码,请补充完整,以保证测试程序正常运行。 裁判测试程序样例: import java.util.Scanner; /* 请在这里补充代码 */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String name = in.next(); String color = in.next(); double price = in.nextDouble(); Flower flower1 = new Flower(name,color,price); Flower flower2 = new Flower(); flower1.printInfo(); flower2.printInfo(); in.close(); } }
时间: 2023-06-19 20:05:51 浏览: 181
深度学习数据集之图像分类数据集:常见102花图像分类数据集(102分类)
补充完整的代码如下:
```java
public class Flower {
private String name;
private String color;
private double price;
public Flower() {
name = "";
color = "";
price = 0.0;
}
public Flower(String name, String color, double price) {
this.name = name;
this.color = color;
this.price = price;
}
public void printInfo() {
System.out.println("name: " + name);
System.out.println("color: " + color);
System.out.println("price: " + price);
}
}
```
阅读全文