public Passenger(string f, string l, Location opos, Location dpos) { this.firstname = f; this.lastname = l; this.origin = opos; this.destination = dpos; this.distance = Math.Round(Geolocator.getDistance(this.origin, this.destination), 2); this.price = Math.Round(this.distance * 1.25, 2); }
/*--------------------------------------------------------- * Constructor * Parameters: * f, l - first and lastnames * c0, s0 - origin city and statecode * c1, s1 - destination city and statecode * *--------------------------------------------------------*/ public Passenger(string f, string l, string c0, string s0, string c1, string s1) { this.firstname = f; this.lastname = l; this.origin = Geolocator.findCoords(c0, s0); this.destination = Geolocator.findCoords(c1, s1); this.distance = Math.Round(Geolocator.getDistance(this.origin, this.destination), 2); this.price = Math.Round(this.distance * 1.25, 2); }
/*--------------------------------------------------------- * Method: travel * * Purpose: move the plane to another location * * Returns: true if the plane is able to reach destination * false if the plane does not have enough fuel *--------------------------------------------------------*/ public bool travel(Location dest) { double difference = Geolocator.getDistance(this.position, dest); if (this.fuel - difference < 0) { this.refuel(); } this.fuel -= difference; this.distance += difference; this.cost += difference * rate; this.timeElapsed += difference / speed; this.position = dest; this.land(); return(true); }
static public void Main(string[] args) { double MONIES = 0; List <Passenger> people; List <Airport> airports = new List <Airport>(); if (args.Length > 0) { people = readCSV(args[0]); } else { people = getPassengers(); } Console.WriteLine("--------------------------------"); Console.WriteLine("PASSENGERS"); Console.WriteLine("--------------------------------"); foreach (Passenger p in people) { Console.WriteLine("\t" + p); } airports = getAirports(people, airports); Console.WriteLine("--------------------------------"); Console.WriteLine("AIRPORTS"); Console.WriteLine("--------------------------------"); foreach (Airport port in airports) { Console.WriteLine(port); } // get the starting airport Airport next = airports[0]; foreach (Airport port in airports) { if (port.departing.Count > next.departing.Count) { next = port; } } Console.WriteLine("STARTING AIRPORT: " + next.name); // instantiate plane at the starting airport Airplane airplane = new Airplane(next.position); Console.WriteLine("--------------------------------"); Console.WriteLine("ITINERARY"); Console.WriteLine("--------------------------------"); while (airplane.timeElapsed < 15 && airports.Count > 0) // && airplane.passengers.Count>0) { // add new passengers { for (int i = 0; i < next.departing.Count; i++) { airplane.passengers.Add(next.departing[i]); Console.WriteLine("\tBoarding: " + next.departing[i].firstname); next.departing.Remove(next.departing[i]); i--; } // kick out passengers for (int i = 0; i < next.arriving.Count; i++) { if (airplane.passengers.Contains(next.arriving[i])) { airplane.passengers.Remove(next.arriving[i]); Console.WriteLine("\tUnloading: " + next.arriving[i].firstname); MONIES += next.arriving[i].price; next.arriving.Remove(next.arriving[i]); i--; } } // print status of plane Console.WriteLine(airplane); // remove useless airports if (next.arriving.Count < 1 && next.departing.Count < 1) { airports.Remove(next); } // pick and travel to the next airport Airport current = next; double distance = 3000; foreach (Airport port in airports) { double tmp = Geolocator.getDistance(current.position, port.position); List <Passenger> common = checkItBeach(port.arriving, airplane.passengers); if (tmp > 0 && tmp < distance && (common.Count > 0 || port.departing.Count > 0)) { next = port; distance = tmp; } } if (next != current) { Console.WriteLine("GOING TO --> " + next.position.city + ", " + next.position.state + " | " + next.name + " at " + next.position.latitude + ", " + next.position.longitude); Console.WriteLine(distance + " miles away"); airplane.travel(next.position); } } Console.WriteLine("--------------------------------"); Console.WriteLine("RESULTS"); Console.WriteLine("--------------------------------"); Console.WriteLine(airplane); Console.WriteLine("INCOME = " + MONIES); Console.WriteLine("LOSS = " + airplane.cost); Console.WriteLine("PROFIT = " + (MONIES - airplane.cost)); }