コード例 #1
26
ファイル: tower.py プロジェクト: ConorMB93/Python1
class Tower:
    __flightClearance = False
    flightList = ["0001a", '0001b', '0001c', '0001d', '0001e']
    flightNum = ""
    __fuelCheck = False
    # Testing airplane codes are correct and adding them to a list of correct codes.
    # Codes can be added also.

    def __init__(self):
        self.anAirplane = Aircraft()

    def currentFlightList(self):
        for plane in self.flightList:
            print(plane)

    def updateFlightList(self, flightNum):
        # testing new flight codes are of correct format
        while True:
            if len(flightNum) == 5:
                if flightNum not in self.flightList:
                    print("Flight code", flightNum, "does not appear to be on our system.")
                    self.add_to_system = input("Do you wish to be added to the updated system?")
                else:
                    print("Flight code", flightNum, " is in our system.")
                    break
                if self.add_to_system == "y":
                    self.flightList.append(flightNum)
                    self.currentFlightList()
                    break
                else:
                    print("Flight number not added to system.")
                    break



    # Checks flight codes are correct.
    def checkFlightList(self):
        print("")
        while True:
            for plane in self.flightList:
                print(plane)
            check = input("Flight list check correct?")
            if check == "y":
                print("Flight list authorization complete.")
                break
            else:
                removeFlight = input("Enter flight number that you wish to remove:")
                if removeFlight in self.flightList:
                    self.flightList.remove(removeFlight)
                    print("Flight number", removeFlight, "was deleted from flight list system.")
                else:
                    print("Invalid flight number entered.")
                    print("Please enter a authorized flight code.")

    def requestFlightCheck(self):
        self.anAirplane.flightNum = input("Enter flight number: ")
        if len(self.anAirplane.flightNum) == 5:
            if self.anAirplane.flightNum not in self.flightList:
                print("Flight code", self.anAirplane.flightNum, "does not appear to be on our system.")
                self.add_to_system = input("Do you wish to be added to the updated system?")
                if self.add_to_system == "y":
                    self.flightList.append(self.anAirplane.flightNum)
                    self.currentFlightList()
                else:
                    print("Flight number not added to system.")

            else:
                # Create anAirplane object and grant clearance
                print("Flight code", self.anAirplane.flightNum, "is in our system.")

                #check fuel
                self.anAirplane.fuelCheck()

                if self.__fuelCheck == False:
                    print("Refueling in process .. ")
                    self.anAirplane.addFuel(15000)
                    self.anAirplane.__flightClearance = self.anAirplane.fuelCheck()
                    self.anAirplane.preFlightCheck()
                else:
                    self.anAirplane.__flightClearance = self.anAirplane.fuelCheck()
                    self.anAirplane.preFlightCheck()
コード例 #2
0
ファイル: test1.py プロジェクト: ConorMB93/Python1
from Aircraft import *
from tower import *

myAirplane = Aircraft()
myAirplane.addFuel(500)
myAirplane.printStatus()
myAirplane.takeOff()
print("---")
dublinTower = Tower()
dublinTower.requestFlightCheck()
コード例 #3
0
class Itinerary:

    route = []
    permutationlist = []
    distancesDict = {}
    costDict = {}
    refuelCostDict = {}

    def __init__(self, myAirportList, myAircraft, atlas):
        self.route = [
            atlas.getAirport(myAirportList[0]),
            atlas.getAirport(myAirportList[1]),
            atlas.getAirport(myAirportList[2]),
            atlas.getAirport(myAirportList[3]),
            atlas.getAirport(myAirportList[4])
        ]
        self.aircraft = Aircraft(myAircraft)

    def permutateRoute(self):
        permutations = list(
            itertools.permutations(
                [self.route[1], self.route[2], self.route[3], self.route[4]]))

        for route in permutations:
            self.permutationlist.append(
                ((self.route[0], ) + route + (self.route[0], )))
        return self.permutationlist

    def getCosts(self, atlas):

        for route in self.permutationlist:
            totCost = 0
            for i in range(len(route) - 1):

                rate = float(route[i + 1].country.rateFrom())
                cost = atlas.getDistBetween(route[i].code,
                                            route[i + 1].code) * rate
                totCost += cost
            self.costDict[route] = round(totCost, 2)
        return self.costDict

    def getLowestCostRoute(self):
        return min(self.costDict, key=self.costDict.get)

    def getDistances(self, atlas):

        for route in self.permutationlist:
            totDistance = 0

            for i in range(len(route) - 1):

                dist = atlas.getDistBetween(route[i].code, route[i + 1].code)
                totDistance += dist

            self.distancesDict[route] = round(totDistance, 2)
        return self.distancesDict

    def getLowestDistRoute(self):
        return min(self.distancesDict, key=self.distancesDict.get)

    def getRefuelCosts(self, atlas):

        for route in self.permutationlist:
            self.aircraft.addFuel(self.aircraft.MIN_FUEL)
            totCost = self.aircraft.MIN_FUEL
            for i in range(len(route) - 1):
                if atlas.getDistBetween(
                        route[i].code,
                        route[i + 1].code) <= self.aircraft.getRange():
                    if self.aircraft.fuel < (atlas.getDistBetween(
                            route[i].code, route[i + 1].code)) * 1.1:
                        rate = float(route[i].country.rateFrom())
                        cost = ((atlas.getDistBetween(
                            route[i].code, route[i + 1].code)) * 1.1 -
                                self.aircraft.fuel) * rate
                        totCost += cost
                        self.aircraft.addFuel(((atlas.getDistBetween(
                            route[i].code, route[i + 1].code)) * 1.1) -
                                              self.aircraft.fuel)
                        self.aircraft.fly(
                            atlas.getDistBetween(route[i].code,
                                                 route[i + 1].code))
                    else:
                        self.aircraft.fly(
                            atlas.getDistBetween(route[i].code,
                                                 route[i + 1].code))
                else:
                    totCost = 99999999999.99
            self.refuelCostDict[route] = round(totCost, 2)
        return self.refuelCostDict

    def getRefuelCostRoute(self):
        if self.refuelCostDict.get(
                min(self.refuelCostDict,
                    key=self.refuelCostDict.get)) > 9999999999.99:
            return "ERROR"
        else:
            return min(self.refuelCostDict, key=self.refuelCostDict.get)

    def costMinCalculator(self):
        return self.costDict.get(min(self.costDict, key=self.costDict.get))

    def distMinCalculator(self):
        return self.distancesDict.get(
            min(self.distancesDict, key=self.distancesDict.get))

    def refuelMinCalculator(self):
        if self.refuelCostDict.get(
                min(self.refuelCostDict,
                    key=self.refuelCostDict.get)) > 9999999999.99:
            return "Plane range too short for this route"
        else:
            return self.refuelCostDict.get(
                min(self.refuelCostDict, key=self.refuelCostDict.get))
コード例 #4
0
class Itinerary:

    route = []
    permutationlist = []
    distancesDict = {}
    costDict = {}
    refuelCostDict = {}

    def __init__(self, myAirportList, myAircraft, atlas):
        self.route = [atlas.getAirport(myAirportList[0]), atlas.getAirport(myAirportList[1]),
                          atlas.getAirport(myAirportList[2]),atlas.getAirport(myAirportList[3]),
                            atlas.getAirport(myAirportList[4])]
        self.aircraft = Aircraft(myAircraft)

    def permutateRoute(self):
        permutations = list(itertools.permutations([self.route[1], self.route[2], self.route[3], self.route[4]]))

        for route in permutations:
            self.permutationlist.append(((self.route[0],) + route + (self.route[0],)))
        return self.permutationlist

    def getCosts(self, atlas):

        for route in self.permutationlist:
            totCost = 0
            for i in range(len(route)-1):

                rate = float(route[i+1].country.rateFrom())
                cost = atlas.getDistBetween(route[i].code, route[i+1].code)*rate
                totCost += cost
            self.costDict[route] = round(totCost,2)
        return self.costDict

    def getLowestCostRoute(self):
        return min(self.costDict, key=self.costDict.get)

    def getDistances(self, atlas):

        for route in self.permutationlist:
            totDistance = 0

            for i in range(len(route)-1):

                        dist = atlas.getDistBetween(route[i].code, route[i+1].code)
                        totDistance += dist


            self.distancesDict[route]=round(totDistance,2)
        return self.distancesDict

    def getLowestDistRoute(self):
            return min(self.distancesDict, key=self.distancesDict.get)

    def getRefuelCosts(self, atlas):

        for route in self.permutationlist:
            self.aircraft.addFuel(self.aircraft.MIN_FUEL)
            totCost = self.aircraft.MIN_FUEL
            for i in range(len(route)-1):
                if atlas.getDistBetween(route[i].code, route[i+1].code) <= self.aircraft.getRange():
                    if self.aircraft.fuel < (atlas.getDistBetween(route[i].code, route[i+1].code))*1.1:
                        rate = float(route[i].country.rateFrom())
                        cost = ((atlas.getDistBetween(route[i].code, route[i+1].code))*1.1-self.aircraft.fuel)*rate
                        totCost += cost
                        self.aircraft.addFuel(((atlas.getDistBetween(route[i].code, route[i+1].code))*1.1)-self.aircraft.fuel)
                        self.aircraft.fly(atlas.getDistBetween(route[i].code, route[i+1].code))
                    else:
                        self.aircraft.fly(atlas.getDistBetween(route[i].code, route[i+1].code))
                else:
                    totCost = 99999999999.99
            self.refuelCostDict[route] = round(totCost, 2)
        return self.refuelCostDict


    def getRefuelCostRoute(self):
        if self.refuelCostDict.get(min(self.refuelCostDict, key=self.refuelCostDict.get)) > 9999999999.99:
            return "ERROR"
        else:
            return min(self.refuelCostDict, key=self.refuelCostDict.get)






    def costMinCalculator(self):
        return self.costDict.get(min(self.costDict, key=self.costDict.get))

    def distMinCalculator(self):
        return self.distancesDict.get(min(self.distancesDict, key=self.distancesDict.get))

    def refuelMinCalculator(self):
        if self.refuelCostDict.get(min(self.refuelCostDict, key=self.refuelCostDict.get)) > 9999999999.99:
            return "Plane range too short for this route"
        else:
            return self.refuelCostDict.get(min(self.refuelCostDict, key=self.refuelCostDict.get))