In: Computer Science
Submit:
Be sure to:
Dog Walker Program
Programming language: Python
requirement: please follow up the rules per demonstrated above
CODE:
main.py:
from include.Person import Person from include.Dog import Dog from include.Customer import Customer from include.DogWalker import DogWalker #main method def main(): #list of dogs dogs = [] #adding dogs dogs.append(Dog("Brutus","German Shepherd",74.5,4)) dogs.append(Dog("Tommy","Pomerian",54.3,6)) #instantiating dogWalker and Customer objects dogWalker = DogWalker(2.5,"Sam",24,dogs) customer = Customer(43.5,"Bob",3,dogs) #printing the details print('Dog Walker:') print(dogWalker) print('\nCustomer:') print(customer) if __name__ == "__main__": main()
___________________________________________________
Dogs.py
class Dog(): #constructor and member variables def __init__(self,name,breed,weight,hours_walked): self.name = name self.breed = breed self.weight = weight self.hours_walked = hours_walked #setters and getters def setName(self,name): self.name = name def setBreed(self, breed): self.breed = breed def setWeight(self,weight): self.weight = weight def setHoursWalked(self,hours_walked): self.hours_walked = hours_walked def getName(self): return self.name def getBreed(self): return self.breed def getWeight(self): return self.weight def getHoursWalked(self): return self.hours_walked #str method def __str__(self) -> str: return "Name: {}\nBreed:{}\nWeight: {}lbs\nHours Walked: {} hours".format(self.name, self.breed, str(self.weight), str(self.hours_walked))
_________________________________________________
Person.py
class Person(): #person constructor def __init__(self,name,id_number,dogs : list): self.name = name self.id_number = id_number self.dogs = dogs #setters and getters def getName(self): return self.name def getID(self): return self.id_number def getDogs(self): return self.dogs def setName(self,name): self.name = name def setID(self,id_number): self.id_number = id_number def setDogs(self,dogs:list): self.dogs = dogs #str method def __str__(self) -> str: #building the list of dogs string dogString = "" for i,x in enumerate(self.dogs): dogString = dogString + str(x) +'\n' return "Name: {}\nID: {}\nDogs List:\n{}".format(self.name, str(self.id_number), str(dogString)) _____________________________________________________
Customer.py
from include.Person import Person class Customer(Person): #customer class constructor def __init__(self, amount_owed: float,name,id_number,dogs : list): self.amount_owed = amount_owed Person.__init__(self,name,id_number,dogs) #setters and getters def setAmountOwed(self, amount_owed): self.amount_owed = amount_owed def getAmountOwed(self): return self.amount_owed def __str__(self) -> str: return super().__str__()+"\nAmount Owed: ${}".format(str(self.amount_owed))
__________________________________________________
DogWalker.py
from include.Person import Person class DogWalker(Person): #dogWalker class constructor def __init__(self, hourly_rate: float,name,id_number,dogs : list): self.hourly_rate = hourly_rate Person.__init__(self,name,id_number,dogs) #setters and getters def setHourlyRate(self, hourly_rate): self.hourly_rate = hourly_rate def getHourlyRate(self): return self.hourly_rate #str method def __str__(self) -> str: return super().__str__()+"\nHourly Rate: ${}/hour".format(str(self.hourly_rate))
____________________________________________
OUTPUT:
___________________________________________________
Feel free to ask any questions in the comments section
Thank You!