0
String [] cabin_names={"Hetty","Poppy","Blus Skies","Bay View",
                               "Happy Days","Summer Joy","Walkers' Rest",
                               "Bertie","Green Forest Lodge","Coppice Lodge"}; 

int[] cabin_capacity={4,4,4,6,6,6,8,8,10,10};

double[] cabin_peak={400.00,400.00,500.00,650.00,695.00,800.00,950.00,
                             1050.00,1200.00,1500.00};

double[] cabin_offpeak={250.00,250.00,350.00,500.00,550.00,600.00,750.00,
                                850.00,950.00,1150.00};

I've tried to put all these arrays into one array, but they're all different data types.

float[][] array_of_all_cabin_deets={cabin_names,cabin_capacity,cabin_peak,cabin_offpeak};
0

2 Answers 2

2

You can't do that by specifying the types of the arrays, one solution can be is to create a class called Cabin

public class Cabin {
    private String name;
    private int capacity;
    private double peak;
    private double offBeak;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public double getPeak() {
        return peak;
    }

    public void setPeak(double peak) {
        this.peak = peak;
    }

    public double getOffBeak() {
        return offBeak;
    }

    public void setOffBeak(double offBeak) {
        this.offBeak = offBeak;
    }
}

And then create an array of Cabin

    Cabin[] cabins = new Cabin[3];
    Cabin cabin = new Cabin();
    cabin.setName("Hetty");
    cabin.setPeak(4);
    cabin.setOffBeak(250.00);
    cabins[0] = cabin;
Sign up to request clarification or add additional context in comments.

Comments

0

You can achieve it by creating the outer array of type Object

        Object[] genericArray = {cabin_names, cabin_capacity, cabin_peak, cabin_offpeak};

2 Comments

How is that useful? How would you access the fields in the individual arrays given the outer genericArray ?
We will have to type cast to access each field of the array.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.