-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.py
106 lines (84 loc) · 3.27 KB
/
contract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
"""
CSC148, Winter 2019
Assignment 1
This code is provided solely for the personal and private use of
students taking the CSC148 course at the University of Toronto.
Copying for purposes other than this use is expressly prohibited.
All forms of distribution of this code, whether as given or with
any changes, are expressly prohibited.
All of the files in this directory and all subdirectories are:
Copyright (c) 2019 Bogdan Simion, Diane Horton, Jacqueline Smith
"""
import datetime
from math import ceil
from typing import Optional
from bill import Bill
from call import Call
# Constants for the month-to-month contract monthly fee and term deposit
MTM_MONTHLY_FEE = 50.00
TERM_MONTHLY_FEE = 20.00
TERM_DEPOSIT = 300.00
# Constants for the included minutes and SMSs in the term contracts (per month)
TERM_MINS = 100
# Cost per minute and per SMS in the month-to-month contract
MTM_MINS_COST = 0.05
# Cost per minute and per SMS in the term contract
TERM_MINS_COST = 0.1
# Cost per minute and per SMS in the prepaid contract
PREPAID_MINS_COST = 0.025
class Contract:
""" A contract for a phone line
This is an abstract class. Only subclasses should be instantiated.
=== Public Attributes ===
start:
starting date for the contract
bill:
bill for this contract for the last month of call records loaded from
the input dataset
"""
start: datetime.datetime
bill: Optional[Bill]
def __init__(self, start: datetime.date) -> None:
""" Create a new Contract with the <start> date, starts as inactive
"""
self.start = start
self.bill = None
def new_month(self, month: int, year: int, bill: Bill) -> None:
""" Advance to a new month in the contract, corresponding to <month> and
<year>. This may be the first month of the contract.
Store the <bill> argument in this contract and set the appropriate rate
per minute and fixed cost.
"""
raise NotImplementedError
def bill_call(self, call: Call) -> None:
""" Add the <call> to the bill.
Precondition:
- a bill has already been created for the month+year when the <call>
was made. In other words, you can safely assume that self.bill has been
already advanced to the right month+year.
"""
self.bill.add_billed_minutes(ceil(call.duration / 60.0))
def cancel_contract(self) -> float:
""" Return the amount owed in order to close the phone line associated
with this contract.
Precondition:
- a bill has already been created for the month+year when this contract
is being cancelled. In other words, you can safely assume that self.bill
exists for the right month+year when the cancelation is requested.
"""
self.start = None
return self.bill.get_cost()
# TODO: Implement the MTMContract, TermContract, and PrepaidContract
if __name__ == '__main__':
import python_ta
python_ta.check_all(config={
'allowed-import-modules': [
'python_ta', 'typing', 'datetime', 'bill', 'call', 'math'
],
'disable': ['R0902', 'R0913'],
'generated-members': 'pygame.*'
})