Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Introduction Serpent City is an island resort that is implementing an automated system to track revenues and taxes due for three types of businesses: restaurants,

Introduction

Serpent City is an island resort that is implementing an automated system to track revenues and taxes

due for three types of businesses: restaurants, hotels, and convenience stores. You are to write a set of

Python classes that track the revenues and taxes based on the specifications below.

Details

You need to write a set of four Python classes. The structures for these Python classes are described

here:

A parent class of businesses (Business)

-----o This is an abstract class, so this class will have no concrete instance.

-----o All instance variables must be private (that is, they must start with an underscore character).

----------This class needs to keep track of at least four (4) pieces of information:

---------- account number an integer (int)

---------- business name a string (str)

---------- the primary income a floating point value (float)

---------- the secondary income a floating point value (float)

-----o This class must have the following API:

---------- The following are instance methods

--------------- Business (accountNumber, name) # this is the constructor, it creates and registers a business

--------------- getAccountNumber () # return the account number of the business

--------------- setAccountNumber (accountNumber) # set the account number of the business

--------------- getName () # return the name of the business

--------------- setName (name) # set the name of the business

--------------- getPrimaryIncome () # return the accumulated primary income

--------------- getSecondaryIncome () # return the accumulated secondary income

--------------- addPrimaryIncome (amount) # add the amount to the accumulated primary income

--------------- addSecondaryIncome (amount) # add the amount to the accumulated secondary income

--------------- getTaxDue () # abstract method for calculating tax (this method needs to be abstract since every type of business has a different tax calculating scheme)

--------------- report () # return a string that lists the income and tax due (see below for details)

---------- The following are class methods

--------------- registerBusinesses (business) # register the given business so it can be found later

--------------- clearBusinesses () # clear all registered businesses

--------------- getRegisteredBusinesses () # return a list of (registered) businesses, return an empty list if no business has been registered yet

--------------- findBusiness (accountNumber) # find (registered) business by account number, return None if none found

-----o Each type of businesses will have two types of incomes primary income and secondary income.

Each of the primary income and secondary income are defined based on the type of business.

-----o The report () method must return a string that looks like the following (see example output file provided):

---------- The first line shows the account number and name of business

---------- The second line reports the type of this business

---------- The third and the fourth lines display the primary and secondary income, respectively

---------- The fifth line displays the total income

---------- The sixth line shows the calculated tax due.

---------- All floating-point values (incomes and taxes due) should be output with two (2) digits after the decimal points.

Three subclasses, one each for restaurants, hotels, and convenience stores.

-----o These subclasses cannot have instance variables, not even private instance variables class variables that are constants are acceptable.

-----o These subclasses should have a constructor that takes an account number and a name.

-----o These subclasses should also implement the getTaxDue () and the report () method to make the subclasses concrete.

-----o These subclasses should NOT implement these methods: getAccountNumber, setAccountNumber, getName, setName, getPrimaryIncome, getSecondaryIncome, addPrimaryIncome, and addSecondaryIncome. These methods should be implemented in the parent Business and inherited into the subclasses unmodified.

The tax due for a restaurant is calculated as follow:

-----o Primary income is the (non-alcoholic) food income and will be charged a tax of 6%.

-----o Secondary income is the alcoholic income and will be charged a tax of 12%.

-----o If the secondary income is greater than primary income, a surtax of 5% will be charged. This surtax is calculated on the total income.

The tax due for a hotel is calculated as follow:

-----o Primary income is for room income.

-----o Secondary income is for suite income.

-----o The larger of the two types of income will be charged a tax of 15%, while the smaller one will be charged a tax of 12%.

The tax due for a convenience store is calculated as follow:

-----o Primary income is income for everything except newspaper and will be charged a tax of 7%.

-----o Secondary income is income for newspaper and will not be charged of any tax.

Except for those defined in the API described above, all other methods must be private.

There cannot be any import statement in your file.

The tester will do the following: Create five (5) different valid businesses. Read from the data file and add receipts to the businesses. The receipts in the data file is arranged in unpredictable order. All receipts in the file are guaranteed to be valid so no checking is necessary. Calculate and print out the tax due for each registered business

-------------------------The input file is data-small.txt:

101 1 60.05

202 2 67.06

101 1 60.11

202 1 294.89

102 2 37.11

612 1 19.29

201 1 346.48

201 1 434.61

102 1 95.02

101 1 42.95

202 1 323.79

202 1 132.42

202 2 417.85

102 1 58.25

202 1 140.13

202 2 213.64

101 2 37.11

201 2 195.49

101 1 46.93

202 2 92.74

201 2 100.25

202 2 93.35

101 1 43.13

201 1 436.56

202 2 312.19

201 1 172.04

101 2 113.93

201 1 68.71

201 1 322.56

101 2 92.64

202 1 417.07

201 1 186.08

612 1 11.11

201 1 180.14

201 2 208.61

102 2 113.93

201 1 420.53

102 1 29.41

201 1 337.08

612 2 18.41

202 1 212.79

201 2 88.57

102 1 116.25

102 1 108.41

102 2 79.56

101 2 100.36

201 2 231.18

202 1 328.07

612 1 29.94

101 1 39.38

612 1 17.75

101 1 81.53

612 1 46.65

201 2 75.34

202 1 345.94

101 1 80.88

102 1 39.86

201 1 60.57

102 1 103.81

102 1 64.91

202 2 135.71

202 2 269.90

102 1 54.14

612 1 14.62

101 1 77.93

102 1 61.45

201 1 169.86

612 2 5.91

102 2 118.48

612 1 24.15

102 2 101.96

201 1 295.24

102 1 108.96

612 2 18.97

202 1 169.61

201 2 151.62

612 1 5.76

201 2 377.54

101 1 20.29

201 1 388.65

202 2 203.94

201 2 273.66

101 1 44.52

612 2 15.47

202 1 359.10

201 1 112.66

202 1 208.80

102 1 106.50

101 1 67.36

102 2 45.57

201 2 130.56

201 1 196.19

201 1 260.56

612 2 37.60

202 1 251.85

201 2 313.67

102 2 44.06

612 1 8.97

202 1 124.24

612 1 26.74

-------------------------The output file is result-small.txt:

Account Number: 101 (Moe's)

Business Type: Restaurant

Food Income: $665.06

Alcoholic Income: $344.04

Total Receipts: $1009.10

Total Tax Due: $81.19

Account Number: 102 (Joe's)

Business Type: Restaurant

Food Income: $946.97

Alcoholic Income: $540.67

Total Receipts: $1487.64

Total Tax Due: $121.70

Account Number: 201 (Ritz)

Business Type: Hotel

Room Income: $4388.52

Suite Income: $2146.49

Total Income: $6535.01

Total Tax Due: $915.86

Account Number: 202 (Notel Motel)

Business Type: Hotel

Room Income: $3308.70

Suite Income: $1806.38

Total Income: $5115.08

Total Tax Due: $713.07

Account Number: 612 (Six Twelve)

Business Type: Convenience Store

Newspaper Income: $96.36

Non-newspaper Income: $204.98

Total Income: $301.34

Total Tax Due: $14.35

-------------------------The tester class is BusinessTester.py:

image text in transcribed

image text in transcribed

image text in transcribed

def loadClasses (module, path):

global Business, Restaurant, Hotel, ConvenienceStore

import sys

sys.path.insert (0, path)

try:

module = __import__ (module)

Business = getattr (module, 'Business')

Restaurant = getattr (module, 'Restaurant')

Hotel = getattr (module, 'Hotel')

ConvenienceStore = getattr (module, 'ConvenienceStore')

finally:

sys.path.pop (0)

def setupBusiness ():

Business.clearBusinesses ()

# the Business class will keep track all created businesses, no need

to do so here.

Restaurant (101, "Moe's")

Restaurant (102, "Joe's")

Hotel (201, 'Ritz')

Hotel (202, 'Notel Motel')

ConvenienceStore (612, 'Six Twelve')

def process (filename):

f = open (filename)

for line in f:

fields = line.split ()

accountNumber = int (fields [0])

primary = fields [1] == '1'

amount = float (fields [2])

business = Business.findBusiness (accountNumber)

if not business is None:

if primary:

business.addPrimaryIncome (amount)

else:

business.addSecondaryIncome (amount)

f.close ()

def report (filename):

f = open (filename, 'w')

for business in Business.getRegisteredBusinesses ():

f.write (business.report () + ' ')

f.close ()

def compare (file1, file2):

f1 = open (file1)

f2 = open (file2)

return f1.read () == f2.read ()

def test (module = 'Business', path = '.', record = print):

try:

loadClasses (module, path)

except:

record ('File loading error - testing not executed.')

return 0

score = 0

for file in ('small', 'medium', 'large'):

setupBusiness ()

infile = 'data-' + file + '.txt'

outfile = 'my-result-' + file + '.txt'

reffile = 'result-' + file + '.txt'

try:

process (infile)

report (outfile)

if (compare (outfile, reffile)):

record ('Processing %s: passed.' % infile)

score = score + 3

else:

record ('Processing %s: failed, please compare the

files %s and %s' % (infile, outfile, reffile))

except Exception as err:

t = type (err).__name__

record ('Exception caught when processing %s.' % infile)

record ('Exception type: %s' % t)

record ('Exception message: %s' % err)

return score

if __name__ == '__main__':

test ()

BusinessTester.pyE O history 1 E def loadClasses (module, path): 2 global Business, Restaurant, Hotel, ConvenienceStore import sys sys.path.insert (e, path) try: 4 moduleimport (module) Businessgetattr (module, 'Business') Restaurantgetattr (module, 'Restaurant') Hotel getattr (module, 'Hotel') ConvenienceStore -getattr (module, 'ConvenienceStore') 6 7 8 9 10 11 E 12 13 14 E def setupBusiness (: 15 16 17 18 19 20 21 finally: sys.path.pop (e) Business.clearBusinesses () # the Business class will keep track all created businesses, no need to do so here Restaurant (101, "Moe's") Restaurant (102, "Joe's") Hotel (201, 'Ritz') Hotel (202, 'Notel Motel') ConvenienceStore (612, 'SIX Twelve') 23 E def process (filename): 24 25 E 26 27 f-open (filename) for line in f: fields-line.split () accountNumber int (fields [e]) 28 29 30 31 32 primary - fields [1 1 amountfloat (fields [2]) businessBusiness.findBusiness (accountNumber) if not business is None: if primary: business.addPrimaryIncome (amount) 34 35 36 37 38 def report (filename): 39 40 41 42 43 44 def compare (file1, file2): 45 46 47 48 49 def test (module = 'Business', path = '.', record = print): 50 51 52 53 54 else: business.addSecondaryIncome (amount) f.close () f open (filename, 'w) for business in Business.getRegisteredBusinesses (): f.write (b usiness.reportnn f.close f1open (file1) f2open (file2) return f1.read () == f2.read () try: loadClasses (module, path) except record ('File loading error - testing not executed.') return e BusinessTester.pyE O history 1 E def loadClasses (module, path): 2 global Business, Restaurant, Hotel, ConvenienceStore import sys sys.path.insert (e, path) try: 4 moduleimport (module) Businessgetattr (module, 'Business') Restaurantgetattr (module, 'Restaurant') Hotel getattr (module, 'Hotel') ConvenienceStore -getattr (module, 'ConvenienceStore') 6 7 8 9 10 11 E 12 13 14 E def setupBusiness (: 15 16 17 18 19 20 21 finally: sys.path.pop (e) Business.clearBusinesses () # the Business class will keep track all created businesses, no need to do so here Restaurant (101, "Moe's") Restaurant (102, "Joe's") Hotel (201, 'Ritz') Hotel (202, 'Notel Motel') ConvenienceStore (612, 'SIX Twelve') 23 E def process (filename): 24 25 E 26 27 f-open (filename) for line in f: fields-line.split () accountNumber int (fields [e]) 28 29 30 31 32 primary - fields [1 1 amountfloat (fields [2]) businessBusiness.findBusiness (accountNumber) if not business is None: if primary: business.addPrimaryIncome (amount) 34 35 36 37 38 def report (filename): 39 40 41 42 43 44 def compare (file1, file2): 45 46 47 48 49 def test (module = 'Business', path = '.', record = print): 50 51 52 53 54 else: business.addSecondaryIncome (amount) f.close () f open (filename, 'w) for business in Business.getRegisteredBusinesses (): f.write (b usiness.reportnn f.close f1open (file1) f2open (file2) return f1.read () == f2.read () try: loadClasses (module, path) except record ('File loading error - testing not executed.') return e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started