0

I have a question! I don`t know How can I retur the array? I want to use get and set.

 TypeOfWater[] waters = returnTypes1();

public String[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}


private static TypeOfWater[] returnTypes1()
{
    TypeOfWater[] type = new TypeOfWater[4];
    type[0] = new TypeOfWater();
    type[0].name = "1)Fanta";
    type[0].cost = 11;

    type[1] = new TypeOfWater();
    type[1].name = "2)Coca";
    type[1].cost = 12;

    type[2] = new TypeOfWater();
    type[2].name = "3)Sprite";
    type[2].cost = 14;

    type[3] = new TypeOfWater();
    type[3].name = "4)Orange juice";
    type[3].cost = 22;

    return type;
}

Please, help me. I am new at java programming.

3 Answers 3

1

You should change

public String[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}

for

public TypeOfWater[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}
Sign up to request clarification or add additional context in comments.

Comments

0

The type of your return is not the good!

Water is TypeOfWater[] and your getTypeOfWater method return a String[]

So, try to change your String[] by a TypeOfWater[]

Comments

0

The return data type of getTypeOfWater() is incorrect. It's set to return String[] when it should be returning TypeOfWater[]

getTypeOfWater() is also a misleading function name if you're trying to return the array itself. If that's the case, the function should be renamed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.