class HotelRoomCalc(object):
    'Hotel room rate calculator'
    
    def __init__(self, rt, sales = 0.085, rm = 0.1):
        '''HotelRoomCalc default arguements:
        sales tax == 8.5% and room tax == 10% '''
        self.salesTax = sales
        self.roomTax = rm
        self.roomRate = rt
        
    def calcTotal(self, days =1):
        'Calcultate total; default to daily rate'
        daily = round((self.roomRate * 
                       (1 + self.roomTax + self.salesTax)), 2)
        return float(days) * daily
    
sfo = HotelRoomCalc(299)
print 'Instance San Francisco'
print 'Daily rate $', sfo.calcTotal()
print '2-day rate $', sfo.calcTotal(2)

sea = HotelRoomCalc(189, 0.086, 0.058)
print '\nInstance Seattle'
print 'Daily rate $', sea.calcTotal()
print '2-day rate $', sea.calcTotal(4)

wasWkDay = HotelRoomCalc(169, 0.045, 0.02)
wasWkEnd = HotelRoomCalc(119, 0.045, 0.02)
print '\nWashington, D.C. '
print '$', wasWkDay.calcTotal(5) + wasWkEnd.calcTotal()
    

运行结果

Instance San Francisco
Daily rate $ 354.31
2-day rate $ 708.62

Instance Seattle
Daily rate $ 216.22
2-day rate $ 864.88

Washington, D.C. 
$ 1026.63

 

posted on 2012-08-21 07:45  balian  阅读(274)  评论(0编辑  收藏  举报