I currently have the following HashMap in a Holiday class.
Holiday Class:
HashMap <String, Location> holidays = new HashMap<String, Location>();
This creates an instance of the Location class, to allow more fields to be shown.
Location class:
public class Location {
private String locationName;
private String locationDesc;
private double price;
private int quantity;
public Location(String locationName, String locationDesc, double price) {
this.locationName = locationName;
this.locationDesc = locationDesc;
this.price = price;
quantity = 0;
}
public String toString() {
return (locationName + " | " + "£" + price);
}
public double getPrice() { return price; }
public String getLocationName() { return locationName; }
public String getLocationDesc() { return locationDesc; }
public int getQuantity() { return quantity; }
}
In my GUI class I just use the .get HashMap method, this will return the toString. e.g
GUI class
private Holiday holiday;
...
return holiday.holidays.get(--HashMap key here--);
this will return the toString, which is locationName and price.
However. I'm wanting to also print out the HashMap elsewhere, but with returning different fields. such as returning the Description and quantity as well as locationName and price. How would i go about doing this? Or how do i return the individual fields from the Location class which is an instance of in the HashMap.
MANAGED TO DO THIS. But need help with the following below
Second EDIT:
I have a set quantity method in my Location class, to set the amount of bookings for each holiday. However when using;
for (Location location : holiday.holidays.values()) {
location.setQuantity(Integer.parseInt(textFieldQuantity.getText()));
}
This changes all of the holidays to the same quantity when setting each location with a different quantity. How do i fix this?