Question
**USING JAVA** Implement the missing logic in Airport and WNAirService by looking for TODO tags: Contents for WNAirlineService.java: import java.util.HashMap; /** * Southwest Airlines */
**USING JAVA**
Implement the missing logic in Airport and WNAirService by looking for TODO tags:
Contents for WNAirlineService.java:
import java.util.HashMap;
/** * Southwest Airlines */
public class WNAirlineService implements AirlineService {
public static final int BOEING_737_300_SEATS = 148; private static HashMap < String, Integer > flightSeatsBooked;
private WNAirlineService() { flightSeatsBooked = new HashMap < String, Integer > (); }
/** * @TODO create a singleton for WNAirline Service * * @return */ public static WNAirlineService getInstance() { return INSTANCE; }
@Override /** * @TODO define booking flight based on number of seats requested. * For a given flightToBook, if num of seat requested is less than * BOEING_737_300_SEATS then return false since we can not book that many * seats. * Otherwise, check to see if the flight was already booked before, if not * then add the num of seats to the number of seats booked and return * true.@interface * Otherwise, if the flight was already booked before, then check if the * numberOfSeats requested is larger than number of seats left, if it is * then return false * Otherwise, add the numofseats requested to number of seats already * taken and return true * number of seats already taken */ public boolean bookFlight(FlightInfo flightToBook, int numOfSeats) { return false; } private static final WNAirlineService INSTANCE = new WNAirlineService(); }
Contents for FlightInfo.java:
public class FlightInfo { private final String flightNum; private final Airport origination; private final Airport destination;
public FlightInfo(String flightNum, Airport origination, Airport destination) { this.flightNum = flightNum; this.origination = origination; this.destination = destination; }
public String getFlightNum() { return flightNum; }
public Airport getOrigination() { return origination; }
public Airport getDestination() { return destination; }
@Override public String toString() { return "FlightInfo{" + "origination=" + origination + ", destination=" + destination + '}'; }
@Override public int hashCode() { return flightNum.hashCode(); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final FlightInfo other = (FlightInfo) obj; return this.flightNum.equals(other.flightNum); }
}
Contents for Airport.java (It will need updates since there are associated JUnit test. However, there are no TODO in this file because those are methods that are overridden):
public class Airport { private String code; private String name; private String city; private String state;
private String toString;
public Airport(String code, String name, String city, String state) { this.code = code; this.name = name; this.city = city; this.state = state; }
/** * @return String return the code */ public String getCode() { return code; }
/** * @return String return the name */ public String getName() { return name; }
/** * @return String return the city */ public String getCity() { return city; }
/** * @return String return the state */ public String getState() { return state; }
}
Contents for AirlineService.java:
public interface AirlineService { /** * Attempts to book a flight by trying to reserve number of seats * * @param flightToBook * @return true if one was successful in booking a flight, false if was not */ public boolean bookFlight(FlightInfo flightToBook, int numOfSeats); }
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started