-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.cpp
More file actions
117 lines (100 loc) · 2.15 KB
/
worker.cpp
File metadata and controls
117 lines (100 loc) · 2.15 KB
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
107
108
109
110
111
112
113
114
115
116
//
// worker.cpp
// Test Product
//
// Created by David Brown on 05/06/2017.
// Copyright © 2017 David Brown. All rights reserved.
//
#include "account.hpp"
Worker::Worker()
{
gov = Government::Instance();
employer = nullptr;
period_hired = -1;
period_fired = 0;
init();
}
void Worker::init()
{
wages = 0;
benefits = 0;
purchases = 0;
inc_tax = 0;
}
bool Worker::isEmployed()
{
return (employer != nullptr);
}
bool Worker::isEmployedBy(Account *emp)
{
return (emp != nullptr && emp == employer);
}
void Worker::setPeriodHired(int period)
{
period_hired = period;
}
bool Worker::isNewHire(int period)
{
return period_hired == period;
}
Firm *Worker::getEmployer()
{
return employer;
}
void Worker::trigger(int period)
{
if (period > last_triggered) // to prevent double counting
{
last_triggered = period;
int purch = (balance * settings->getPropCon()) / 100;
if (purch > 0 && transferTo(reg->selectRandomFirm(), purch, this))
{
purchases += purch;
}
}
}
void Worker::credit(int amount, Account *creditor)
{
Account::credit(amount);
if (isEmployedBy(creditor))
{
// Here we assume that if the creditor is our employer then we should
// pay income tax. If the creditor isn't our employer but we're
// receiving the payment in our capacity as Worker then it's probably
// benefits or bonus. If not employed at all it must be bonus and we are
// flagged for deletion. Surprising but perfectly possible.
int tax = (amount * settings->getIncTaxRate()) / 100;
transferTo(gov, tax, this);
wages += amount;
inc_tax += tax;
}
else if (creditor == gov)
{
benefits += amount;
}
else
{
std::cout << "*** Unknown reason for credit ***\n";
exit(100);
}
}
int Worker::getWagesReceived()
{
return wages;
}
int Worker::getBenefitsReceived()
{
return benefits;
}
int Worker::getPurchasesMade()
{
return purchases;
}
void Worker::setEmployer(Firm *emp)
{
employer = emp;
}
int Worker::getIncTaxPaid()
{
return inc_tax;
}