我的驱动程序类不会编译。它一直说我给出了错误的类型。我已经在Phone类中声明了变量,然后在驱动程序中创建了有关手机的信息,并希望将其存储在数组中。
电话课程
public class Phone extends Technology {
private String name;
private String type;
private String colour;
private int inStock=10;
private int sold;
//Constructor
public Phone (String itemsId, String brand, double price, String name, String type, String colour ) {
super(itemsId, brand, price );
this.name = name;
this.type = type;
this.colour = colour;
} }
这是不会编译的驱动程序类的一部分,我无法弄清楚我做错了什么。我已按照手机类中的顺序创建了有关手机的信息。
// Creating 10 phones and storing in arrayList
public void pickPhone(){
Phone phone = new Phone("A223","Apple", "€679.00 ", "iPhone 5s", "Smartphone ", " Black");
phoneList.add(phone);
phone = new Phone("A252","Apple", " €649.00 ", " iPhone 5s", "Smartphone ", " White");
phoneList.add(phone);
phone = new Phone("A264","Apple", " €329.00 ", " iPhone 4s", "Smartphone ", " Black");
phoneList.add(phone);
phone = new Phone("S586","Sony", " €570.00 ", " Xperia Z1", "Smartphone ", " Black");
phoneList.add(phone);
phone = new Phone("S549","Sony", " €260.00 ", " Xperia SP", "Smartphone ", " Black");
phoneList.add(phone);
phone = new Phone("G359","Samsung", " €530.00 ", "Galaxy S4", "Smartphone ", " Black");
phoneList.add(phone);
phone = new Phone("G375","Samsung", " €530.00 ", "Galaxy S4", "Smartphone ", "White");
phoneList.add(phone);
phone = new Phone("G352","Samsung", " €350.00 ", "Galaxy S4 Mini", "Smartphone ", "White");
phoneList.add(phone);
phone = new Phone("H488"," HTC ", " €529.00 ", "One", "Smartphone ", "Black");
phoneList.add(phone);
phone = new Phone("H463"," HTC ", " €419.00 ", "One Mini ", "Smartphone ", "Silver");
phoneList.add(phone);
}
答案 0 :(得分:3)
在你的构造函数
中public Phone (String itemsId, String brand, double price, String name, String type, String colour )
price
是双倍的,但您传递了一个字符串,例如" €419.00 "
您必须通过价格,例如419.0
(没有欧元符号,没有空格,周围没有双引号)。
Phone phone = new Phone("A223","Apple", 679.0, "iPhone 5s", "Smartphone ", " Black");
phoneList.add(phone);
答案 1 :(得分:1)
你的错误是你在电话构造函数中要求双倍而不是字符串的价格
例如“€679.00”是一个字符串。如果你想要一个双倍,你必须通过679.00
你必须修改你的构造函数或修改你的参数