Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/travel-bargains/
- Ex 2: Travel Bargains
- Create a new project and class in Eclipse called TravelBargains, with the following structure:
- public class TravelBargains {
- /**
- * Construct a new TravelBargains object with the given graph as the flight plan
- */
- public TravelBargains(WeightedGraph g);
- /**
- * Given a country’s name, find the name of the cheapest country you can fly directly to from here
- */
- public String getCheapestDestination(String currentCountry);
- }
- getCheapestDestination() should return the directly connected country with the lowest flight price.
- If there is a tie, return any country with this minimum price. If the country has no destinations, return null.
- For example, consider the following flight plan:
- Australia ? USA for $1128
- Australia ? UK for $2239
- UK ? France for $102
- UK ? Australia for $2102
- USA ? France for $930
- USA ? Germany for $930
- Here, the cheapest country you can reach from Australia is the USA, which is only $1128. So getCheapestDestination(“Australia”) should return “USA”.
- 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.
- Implement this class, then check your travel system is working with the following tests:
- Ensure that getCheapestDestination() returns null for any country in a system with an empty graph as the flight plan
- Ensure that getCheapestDestination() returns the correct country for each of the 5 countries (Australia, USA, UK, France & Germany) in the flight plan above
- Download: http://solutionzip.com/downloads/travel-bargains/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement