-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperator.java
84 lines (68 loc) · 2.19 KB
/
Operator.java
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
package question;
public class Operator {
//DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE
private int ID;
private double talkingCharge, messageCost, networkCharge;
private int discountRate;
private int totalMessagesQuantity, totalTalkingTime;
private double totalNetworkUsage;
public Operator (int ID, double talkingCharge, double messageCost , double networkCharge, int discountRate) {
this.ID=ID;
this.talkingCharge=talkingCharge;
this.messageCost=messageCost;
this.networkCharge=networkCharge;
this.discountRate=discountRate;
this.totalMessagesQuantity=0;
this.totalNetworkUsage=0;
this.totalTalkingTime=0;
}
/** This method, calculates the talking cost for given operator.
* if the customer is older than 65 or younger than 18, then the operator makes a discount for a customer.
*/
public double calculateTalkingCost (int minute, Customer customer) {
if (customer.getAge()>65 || customer.getAge()<18) {
return ((double) minute*talkingCharge*(1-(double)discountRate*0.01));
}
else {
return ((double) minute*talkingCharge);
}
}
/** This method calculates the message cost for given operator.
* if both customers are using the same operator, customer has discount on his/her messages.
*/
public double calculateMessageCost (int quantity, Customer customer, Customer other) {
if (customer.getOperator() == other.getOperator()) {
return ((double) quantity * messageCost * (1-(double) discountRate * 0.01));
}
else {
return ((double) quantity * messageCost);
}
}
/**
* This method calculates the connection cost for given operator.
* @param amount MB spent
* @return
*/
public double calculateNetworkCost (double amount) {
return (amount * networkCharge);
}
public void timeAdd (int minute) {
totalTalkingTime += minute;
}
public void messageAdd (int quantity) {
totalMessagesQuantity += quantity;
}
public void networkAdd (double usage) {
totalNetworkUsage += usage;
}
public int getTotalMessagesQuantity() {
return totalMessagesQuantity;
}
public int getTotalTalkingTime() {
return totalTalkingTime;
}
public double getTotalNetworkUsage() {
return totalNetworkUsage;
}
//DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE
}