Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal:
- __name = "";
- __family = "";
- def __init__(self, name, family):
- self.__name = name;
- self.__family = family;
- def getName(self):
- return self.__name;
- def getFamily(self):
- return self.__family;
- class Farm:
- __size = 0;
- __name = "";
- __farm_array = [None];
- def __init__(self, size, name):
- self.__size = size;
- self.__name = name;
- def setSize(self, size):
- self.__size = size;
- self.__farm_array = [None] * size;
- def getSize(self):
- return self.__size;
- def setName(self, name):
- self.__name = name;
- def getName(self):
- return self.__name;
- def addAnimal(self, animal):
- self.__farm_array.append(animal);
- def displayFarm(self):
- print("\n-----------------");
- print("Displaying Farm:", self.__name);
- print("-----------------\n");
- for i in range(0, self.__size):
- print("Animal #", i + 1, "'s Name:", self.__farm_array[i - self.__size].getName());
- print("Animal #", i + 1, "'s Family:", self.__farm_array[i - self.__size].getFamily(), "\n");
- farm_size = int(input("Enter Size of Farm: "));
- farm_name = input("Enter Name of Farm: ");
- new_farm = Farm(farm_size, farm_name);
- for i in range(0, farm_size):
- ani_name = input("\nEnter Animal Name: ");
- ani_family = input("Enter Animal Family: ");
- new_ani = Animal(ani_name, ani_family);
- new_farm.addAnimal(new_ani);
- new_farm.displayFarm();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement