user3537296
user3537296

Reputation: 23

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

}

Upvotes: 0

Views: 100

Answers (2)

user43968
user43968

Reputation: 2129

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. if you want a double you have to pass 679.00

you have to modify your constructor or to modify your argument

Upvotes: 1

Eric J.
Eric J.

Reputation: 150108

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 e.g. " €419.00 "

You would have to pass the price as e.g. 419.0 (no Euro sign, no spaces, no double-quotes around it).

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

Upvotes: 3

Related Questions