bigbaddevil7
bigbaddevil7

Reputation: 57

Accessing and changing objects in a predefined array

I am currently trying to make a simulation Seat that a player will be able to sit. The current seats are stored in an array with the X,Y,Z and boolean for if they are full.

That is some of the predefined Seats. I would like to be able to access that array and change the false to true when needed.

Seat[] seats = new Seat[]{
        new Seat(-2,64,16,false),
        new Seat(-3,64,16,false),
        new Seat(-4,64,15,false)
};

This is my Seat class.

public class Seat {

    int x, y, z;
    boolean isFull;

    public Seat(int x, int y, int z, boolean isFull){
        this.x = x;
        this.y = y;
        this.z = z;
        this.isFull = isFull;
    }

    public int getX(){
        return x;
    }

    public int getY(){
        return y;
    }

    public int getZ(){
        return z;
    }

    public boolean getIsFull(){
        return isFull;
    }

    public void setX(int x){
        this.x = x;
    }

    public void setY(int y){
        this.y = y;
    }

    public void setIsFull(boolean isFull){
        this.isFull = isFull;
    }       
}

Upvotes: 1

Views: 24

Answers (1)

deezy
deezy

Reputation: 1480

Access seat[] just like any other array and call the method setIsFull(). Passing the argument true will "fill" the seat.

For example, seats[0].setIsFull(true); will fill the seat at seats[0].

Upvotes: 1

Related Questions