Below is the code that I have written. I need to know where is the best place put the open and close for the .txt files and also which command to call. The text file and the result as it should look...

1 answer below »


Below is the code that I have written. I need to know where is the best place put the open and close for the .txt files and also which command to call. The text file and the result as it should look are attached.class Business(object): """ Business class represents a business and is an abstract class It has accountNumber,name,primaryIncome, secondaryIncome as private instance variables It has getters and setters for all the above variables It has getTaxDue and report as abstract methods It has registeredBusinesses class variables which is a list """ #list to store different businesses registered_businesses = [] #constructor def __init__(self,account_number,_name): self._account_number = int(account_number) self._name = str(_name) self._primary_income = 0.0 self._secondary_income = 0.0 #getters and setters for every instance variable def get_account_number(self): return self._account_number def set_account_number(self,account_number): self._account_number = account_number def get_name(self): return self._name def set_name(self,name): self._name = name def get_primary_income(self): return self._primary_income def get_secondary_income(self): return self._secondary_income def add_primary_income(self,amount): self._primary_income += amount def add_secondary_income(self,amount): self._secondary_income += amount #abstract method, raises NotImplementedError if not implemented by child classes def get_tax_due(self): raise NotImplementedError("Please Implement this method") #abstract method, raises NotImplementedError if not implemented by child classes def report(self): raise NotImplementedError("Please Implement this method") #classmethod for registering businesses @classmethod def register_businesses(cls,business): cls.registered_businesses.append(business) #classmethod for clearing businesses @classmethod def clear_businesses(cls): cls.registered_businesses = [] #classmethod to get registered businesses @classmethod def get_registered_businesses(cls): return cls.registered_businesses #classmethod for finding a registered businesses @classmethod def find_businesses(cls, account_number): for business in cls.registered_businesses: if business._account_number==account_number: return business return None class Restaurant(Business): """ Restaurant class inherits Business and implements the abstract methods """ #class variables for tax percentages as decimals primary_income_tax = 0.06 secondary_income_tax = 0.12 surtax = 0.05 #constructor, calls parent class constructor def __init__(self,account_number,name): super().__init__(account_number,name) #implementation of abstract method def get_tax_due(self): totalTax = self.get_primary_income() * self.primary_income_tax + self.get_secondary_income()*self.secondary_income_tax if(self.get_secondary_income() > self.get_primary_income()): totalTax += self.surtax * totalTax return totalTax #implementation of abstract method def report(self): line1 = 'Account Number = '+str(self.get_account_number())+', Name = '+str(self.get_name()) #self.__class__.__name__ gives the class name of the object line2 = 'Type of business = '+self.__class__.__name__ line3 = 'Primary Income = %.2f ' % self.get_primary_income() line4 = 'Secondary Income = %.2f ' % self.get_secondary_income() line5 = 'Total Income = %.2f ' % (self.get_primary_income()+self.get_secondary_income()) line6 = 'Tax Due = %.2f ' % self.get_tax_due() return line1 + '\n' +line2 + '\n'+line3 + '\n'+line4 + '\n'+line5 + '\n'+line6 + '\n' class Hotel(Business): """ Hotels class inherits Business and implements the abstract methods """ #class variables for tax percentages as decimals smallerTax = 0.12 largerTax = 0.15 #constructor, calls parent class constructor def __init__(self,account_number,name): super().__init__(account_number,name) #implementation of abstract method def get_tax_due(self): totalTax = 0.0 if(self.get_secondary_income() > self.get_primary_income()): totalTax += (self.largerTax*self.get_secondary_income() + self.smallerTax*self.get_primary_income()) else: totalTax += (self.largerTax*self.get_primary_income() + self.smallerTax*self.get_secondary_income()) return totalTax #implementation of abstract method def report(self): line1 = 'Account Number = '+str(self.get_account_number())+', Name = '+str(self.get_name()) #self.__class__.__name__ gives the class name of the object line2 = 'Type of business = '+self.__class__.__name__ line3 = 'Primary Income = %.2f ' % self.get_primary_income() line4 = 'Secondary Income = %.2f ' % self.get_secondary_income() line5 = 'Total Income = %.2f ' % (self.get_primary_income()+self.get_secondary_income()) line6 = 'Tax Due = %.2f ' % self.get_tax_due() return line1 + '\n' +line2 + '\n'+line3 + '\n'+line4 + '\n'+line5 + '\n'+line6 + '\n' class ConvenienceStore(Business): """ ConvenienceStores class inherits Business and implements the abstract methods """ #class variables for tax percentages as decimals primary_income_tax = 0.07 secondary_income_tax = 0.0 #constructor, calls parent class constructor def __init__(self,account_number,name): super().__init__(account_number,name) #implementation of abstract method def get_tax_due(self): totalTax = self.get_primary_income()*self.primary_income_tax + self.get_secondary_income()*self.secondary_income_tax return totalTax #implementation of abstract method def report(self): line1 = 'Account Number = '+str(self.get_account_number())+', Name = '+str(self.get_name()) #self.__class__.__name__ gives the class name of the object line2 = 'Type of business = '+self.__class__.__name__ line3 = 'Primary Income = %.2f ' % self.get_primary_income() line4 = 'Secondary Income = %.2f ' % self.get_secondary_income() line5 = 'Total Income = %.2f ' % (self.get_primary_income()+self.get_secondary_income()) line6 = 'Tax Due = %.2f ' % self.get_tax_due() return line1 + '\n' +line2 + '\n'+line3 + '\n'+line4 + '\n'+line5 + '\n'+line6 + '\n'if __name__ == "__main__" :
Answered 2 days AfterMar 20, 2022

Answer To: Below is the code that I have written. I need to know where is the best place put the open and close...

Aditya answered on Mar 23 2022
104 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here