简体   繁体   English

JAVA - 不会编译

[英]JAVA - won't compile

My driver class won't compile.我的驱动程序类无法编译。 It keeps saying that I'm giving the wrong types.它一直说我给出了错误的类型。 I have declared the variables in the Phone class and then created information about the phone in the driver and want to store it in the array.我已经在 Phone 类中声明了变量,然后在驱动程序中创建了有关电话的信息,并希望将其存储在数组中。

Phone class电话课

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;
    }   
}

This is the part of the driver class that wont compile, I cant figure out what im doing wrong.这是无法编译的驱动程序类的一部分,我无法弄清楚我做错了什么。 I have created information about the phone in the same order that they are in the phone class.我已经按照电话类中的相同顺序创建了有关电话的信息。

// 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);

}

In your constructor在你的构造函数中

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

price is a double, but you pass a string eg " €419.00 " price是双倍,但您传递了一个字符串,例如" €419.00 "

You would have to pass the price as eg 419.0 (no Euro sign, no spaces, no double-quotes around it).您必须将价格传递为例如419.0 (没有欧元符号,没有空格,周围没有双引号)。

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

your mistake is for the price you ask for a double not a string in your constructor of phone您的错误在于您在电话构造函数中要求双倍而不是字符串的价格

For example "€679.00" is a string.例如“€679.00”是一个字符串。 if you want a double you have to pass 679.00如果你想要双倍,你必须通过 679.00

you have to modify your constructor or to modify your argument你必须修改你的构造函数或修改你的参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM