Question: **USING JAVA** Need help implementing JUnit test cases in Airport.java to run on WNAirlineService.java Contents of Airport.java: public class Airport { private String code; private

**USING JAVA**

Need help implementing JUnit test cases in Airport.java to run on WNAirlineService.java

Contents of Airport.java:

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 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 public boolean bookFlight(FlightInfo flightToBook, int numOfSeats) { if (numOfSeats > BOEING_737_300_SEATS) return false; else { if (flightSeatsBooked.containsKey(flightToBook)) { int numSeatsLeft = BOEING_737_300_SEATS - (int) flightSeatsBooked.get(flightToBook); if (numOfSeats > numSeatsLeft) return false; else { int numSeatsTaken = (int) flightSeatsBooked.get(flightToBook); numSeatsTaken += numOfSeats; flightSeatsBooked.put(flightToBook, numSeatsTaken); return true; } } else { flightSeatsBooked.put(flightToBook, numOfSeats); return true; } } }

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 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!