Advertisement
akosiraff

Travel Bargains

Oct 9th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/travel-bargains/
  3. Ex 2: Travel Bargains
  4. Create a new project and class in Eclipse called TravelBargains, with the following structure:
  5. public class TravelBargains {
  6. /**
  7. * Construct a new TravelBargains object with the given graph as the flight plan
  8. */
  9. public TravelBargains(WeightedGraph g);
  10. /**
  11. * Given a country’s name, find the name of the cheapest country you can fly directly to from here
  12. */
  13. public String getCheapestDestination(String currentCountry);
  14. }
  15. getCheapestDestination() should return the directly connected country with the lowest flight price.
  16. If there is a tie, return any country with this minimum price. If the country has no destinations, return null.
  17. For example, consider the following flight plan:
  18. Australia ? USA for $1128
  19. Australia ? UK for $2239
  20. UK ? France for $102
  21. UK ? Australia for $2102
  22. USA ? France for $930
  23. USA ? Germany for $930
  24. Here, the cheapest country you can reach from Australia is the USA, which is only $1128. So getCheapestDestination(“Australia”) should return “USA”.
  25. You can represent these flight using a directed, weighted graph, with each node representing a country and each edge representing a flight. The direction of the edge shows which country is the source (the tail of the arrow) and which is the destination (the head of the arrow), and the weight of the edge represents the price.
  26. Implement this class, then check your travel system is working with the following tests:
  27. Ensure that getCheapestDestination() returns null for any country in a system with an empty graph as the flight plan
  28. Ensure that getCheapestDestination() returns the correct country for each of the 5 countries (Australia, USA, UK, France & Germany) in the flight plan above
  29.  
  30. Download: http://solutionzip.com/downloads/travel-bargains/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement