gpt4 book ai didi

JAVA - 无法编译

转载 作者:行者123 更新时间:2023-12-01 18:33:29 24 4
gpt4 key购买 nike

我的驱动程序类无法编译。它一直说我给出了错误的类型。我已经在 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);

}

最佳答案

在你的构造函数中

public Phone (String itemsId,  String brand, double price, String name, String type, String colour ) 

price 是一个 double ,但您传递一个字符串,例如“419.00欧元”

您必须传递价格,例如419.0(没有欧元符号,没有空格,周围没有双引号)。

Phone phone = new Phone("A223","Apple", 679.0, "iPhone 5s", "Smartphone ", " Black");
phoneList.add(phone);

关于JAVA - 无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com