//Represents a seat on a plane.
public class Seat {
//The section that the seat is in.
public int sectionId;
public int seatId;
public Seat(int seatId, int sectionId) {
this.seatId = seatId;
this.sectionId = sectionId;
}
}
The above just contains the "settings" I guess for each seat. I'm attempting to call the constructor in a map to pair each unique seat with a seat type (adult/child)/ here is what I came up with:
public enum SeatType {
ADULT,
CHILD;
}
private static Map<Seat, SeatType> map = new LinkedHashMap<>();
public static void main(String[] args) {
int sectionId = 5;
map.put(new Seat(1, 5), SeatType.ADULT);
System.out.println(map.get(new Seat(1, 5)));
execution of this code out prints "null" to the console. I know I could easily create a new object for each seat but that's not really an option as that would mean I'd have to create 200+ objects.
I wasn't expecting it to work but I was looking for an explanation on why it doesn't and perhaps a possible resolution to the problem.
Thanks in advance!(And sorry, still a beginner).