Advertisement
TermSpar

Python Farm

Jun 13th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. class Animal:
  2.     __name = "";
  3.     __family = "";
  4.  
  5.     def __init__(self, name, family):
  6.         self.__name = name;
  7.         self.__family = family;
  8.  
  9.     def getName(self):
  10.         return self.__name;
  11.  
  12.     def getFamily(self):
  13.         return self.__family;
  14.  
  15. class Farm:
  16.     __size = 0;
  17.     __name = "";
  18.     __farm_array = [None];
  19.  
  20.     def __init__(self, size, name):
  21.         self.__size = size;
  22.         self.__name = name;
  23.  
  24.     def setSize(self, size):
  25.         self.__size = size;
  26.         self.__farm_array = [None] * size;
  27.     def getSize(self):
  28.         return self.__size;
  29.  
  30.     def setName(self, name):
  31.         self.__name = name;
  32.     def getName(self):
  33.         return self.__name;
  34.  
  35.     def addAnimal(self, animal):
  36.         self.__farm_array.append(animal);
  37.  
  38.     def displayFarm(self):
  39.         print("\n-----------------");
  40.         print("Displaying Farm:", self.__name);
  41.         print("-----------------\n");
  42.         for i in range(0, self.__size):
  43.             print("Animal #", i + 1, "'s Name:", self.__farm_array[i - self.__size].getName());
  44.             print("Animal #", i + 1, "'s Family:", self.__farm_array[i - self.__size].getFamily(), "\n");
  45.  
  46. farm_size = int(input("Enter Size of Farm: "));
  47. farm_name = input("Enter Name of Farm: ");
  48. new_farm = Farm(farm_size, farm_name);
  49.  
  50. for i in range(0, farm_size):
  51.     ani_name = input("\nEnter Animal Name: ");
  52.     ani_family = input("Enter Animal Family: ");
  53.  
  54.     new_ani = Animal(ani_name, ani_family);
  55.     new_farm.addAnimal(new_ani);
  56.  
  57. new_farm.displayFarm();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement