2017-03-24 3 views
-1

これは私の宿題の一部です。私は造船所のシミュレータを作っています。造船所はコンテナ(リンクされたリスト)で構成され、そのコンテナの内部にはパッケージ(リンクされたリストのコレクションでもあります)があります。基本的には、新しいパッケージを作成するときに、同じ宛先のコンテナが存在しない場合は、次のようなプロパティ(Destination、weightlimit、ID)とパーセル(所有者名、宛先、重量、ID)造船所の内部に新しいコンテナを作り、そのコンテナをコンテナ内に置く。それ以外の場合は、パッケージを対応するコンテナに配置します。コンテナはアルファベット順に並べられており、パッケージは最も軽い順に並べられています。クラスプロパティと保護されたクラスへのアクセス

これはこれまで私が行ってきたことです。私はテストのためにadd_container()を書きましたが、動作しますが、私はそれを必要としません。実際の仕事はadd()メソッドによって行われます。それは動作していないと私は理由を把握することはできません。もしあなたの誰かが私に理由やヒントを与えることができれば、本当に感謝しています。

from random import * 

#Package class 

class Package: 

    def __int__(self, name, destination, weight): 
     self._name = name 
     self._destination = destination 
     self._weight = weight 
     self._Next = None 
     self._ID = 0 

#Container Class 
class Container: 

    def __init__(self, dest): 
     self._dest = dest 
     self._Front = None 
     self._next = None 
     self._Maxweight = 2000 
     self._size = 0 
     self._Identification = 0 


class Shipyard: 

    def __init__(self): 
     self._Front = None 
     self._size = 0 



    def size(self): 
     return self._size 



    def add_container(self, Destination): 

     container = Container(Destination) 

     if self._Front == None: 
      self._Front = container 
      self._size += 1 
      container._Identification = ((randint(1,1999))) 

     elif container._dest < self._Front._dest: 
      container._next = self._Front 
      self._Front = container 
      self._size += 1 
      container._Identification = ((randint(1, 1999))) 

     else: 

      current = self._Front 
      previous = None 

      while current is not None and current._dest < Destination: 
       previous = current 
       current = current._next 

       if current == None: 
        previous._next = container 
        self._size += 1 
        container._Identification = ((randint(1, 1999))) 

       else: 
        container._next = current 
        previous._next = container 
        self._size += 1 
        container._Identification = ((randint(1, 1999))) 



    def is_empty(self): 
     return self._size == 0 



    def container_exists(self, dest): 
     container_found = False 
     First_container = self._Front 

     if First_container == None: 
      pass 

     else: 

      while container_found != True: 
       previous = First_container 
       First_container = First_container._next 

       if previous._dest == dest: 
        container_found = True 
        return True 

       else: 

        return False 




    def printAll(self): 

     current = self._Front 
     while current != None: 
      print(current._dest) 
      current = current._next 



    def add(self, name, destination, weight): 

     package = Package(name, destination, weight) 

     if self.container_exists(destination) == True: 
      current = self._Front 

      while current._dest != destination: 
       current = current._next 


       if current._dest == destination: 

        weightlimit = current._Maxtwiehgt - weight 

        if weightlimit <= 0: 
         print("Container to ", destination, "is full!") 
         return 

        if current._Front == None: 
         current._Front = package 
         current._Maxtweihgt -= weight 
         current._size += 1 
         current._Front._ID = (randint(1,1999)) 

        else: 
         currentPackage = current._Front 
         previousPackage = None 

         while currentPackage._Next!= None: 

          previousPackage = currentPackage 
          currentPackage = currentPackage._Next 

          if currentPackage._weight > weight > previousPackage: 
           package._Next = currentPackage 
           previousPackage._Next = package 
           package._ID = (randint(1,1999)) 
           current._Maxweight -= weight 
           current._size += 1 


     else: 
      container = Container(destination) 

      if self._Front == None: 
       self._Front = container 
       self._Front._Front = package #new package 
       self._Front._Identification = (randint(1,1999)) #container ID 
       self._Front._Maxweight -= weight #container weight 
       self._Front._Front._ID = (randint(1,1999)) #package id 
       self._size += 1 #shipyard size 
       self._Front._size += 1 #container size 


      elif self._Front._dest > destination: 
       container._next = self._Front 
       self._Front = container 
       self._Front._Front = package # new package 
       self._Front._Identification = (randint(1, 1999)) # container ID 
       self._Front._Maxweight -= weight # container weight 
       self._Front._Front._ID = (randint(1, 1999)) # package id 
       self._size += 1 # shipyard size 
       self._Front._size += 1 # container size 


      else: 
       current = self._Front 
       previous = None 

       while current._next != None: 
        previous = current 
        current = current._next 

        if current._dest > destination > previous._dest: 
         container._next = current 
         previous._next = container 
         container._Front = package 
         container._Identification = (randint(1,1999)) 
         container._Maxweight -= weight 
         container._Front._ID = (randint(1,1999)) 
         self._size += 1 
         container._size += 1 




def main(): 

    myYard = Shipyard() 
    myYard.add("Jamie", "Atlanta", 120) 
main() 
+3

ようこそスタックオーバーフロー!最初に[ツアー(http://stackoverflow.com/tour)に参加して[良い質問をする方法](http://stackoverflow.com/help/how-to-ask)を学んで[最小、完全、および検証可能](http://stackoverflow.com/help/mcve)の例を参照してください。そうすれば、私たちがあなたを助けやすくなります。 –

+0

@StephenRauch大変申し訳ございません。私はここで新しく、問題を完全に突きつけました。私の質問は、プログラムがクラッシュする理由を知る必要があり、パッケージクラスが引数を取らないと言うことです。 –

+1

ごめんなさい。ここには多くの人があなたを助けたいと思っています。しかし、私たちがあなたを助けるのを助ける必要があります。それはあなたの問題をちょっと解き放つことを意味します。これを行うと、あなたは自分で答えを見つけることが多いのです。あなたが答えを見つけられない場合、悩まされている問題はしばしば非常に迅速に答えられます。 –

答えて

0

これを書き留め:あなたが見ているエラーは、次のとおりです。

TypeError: object() takes no parameters 

あなたがobject() takes no parametersが表示されたら、それはほとんど常にあなたがコンストラクタをめちゃくちゃにしたことを意味します。

まず、アンダースコアの数を確認します。 2つのアンダースコアが前面にあり、2つが背面にあることを確認してください。

次に、__init__のスペルが正しいことを確認してください。たとえば、__int__という関数を宣言する場合、希望することはできません。 :)

関連する問題