-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtravelExpense.java
More file actions
258 lines (223 loc) · 5.65 KB
/
travelExpense.java
File metadata and controls
258 lines (223 loc) · 5.65 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
public class travelExpense {
//Create constants and variables to be used in the class
private final double DAILY_MEAL = 37.00;
private final double DAILY_PARK = 10.00;
private final double DAILY_TAXI = 20.00;
private final double DAILY_LODGE = 95.00;
private final double MILE_DRIVE = .27;
private int days;
private double meals;
private double airfare;
private double carRentalFee;
private double miles;
private double parkFee;
private double taxiFee;
private double regFee;
private double lodging;
//Create the default no args constructor which sets all values to 0
public travelExpense() {
days = 0;
meals = 0;
airfare = 0.0;
carRentalFee = 0.0;
miles = 0.0;
parkFee = 0.0;
taxiFee = 0.0;
regFee = 0.0;
lodging = 0.0;
}
//Create the Accessor methods
/**
* Accessor for days
* @return
*/
public int getDays() {
return days;
}
/**
* Accessor for airfare
* @return
*/
public double getAirfare() {
return airfare;
}
/**
* Accessor for meals
* @return
*/
public double getMeals() {
return meals;
}
/**
* Accessor for carRentalFee
* @return
*/
public double getCarRental() {
return carRentalFee;
}
/**
* Accessor for miles
* @return
*/
public double getMiles() {
return miles;
}
/**
* Accessor for parkFee
* @return
*/
public double getParkFee() {
return parkFee;
}
/**
* Accessor for taxiFee
* @return
*/
public double getTaxiFee() {
return taxiFee;
}
/**
* Accessor for regFee
* @return
*/
public double getRegFee() {
return regFee;
}
/**
* Accessor for lodging
* @return
*/
public double getLodging() {
return lodging;
}
//Create Mutator methods
/**
* Mutator for days
* @param days
*/
public void setDays(int days) {
this.days = days;
}
public void setMeals(double meals) {
this.meals = meals;
}
/**
* Mutator for airfare
* @param airfare
*/
public void setAirfare(double airfare) {
this.airfare = airfare;
}
/**
* Mutator for carRentall
* @param carRental
*/
public void setCarRental(double carRental) {
carRentalFee = carRental;
}
/**
* Mutator for miles
* @param miles
*/
public void setMiles(double miles) {
this.miles = miles;
}
/**
* Mutator for parkFee
* @param parkFee
*/
public void setParkFee(double parkFee) {
this.parkFee = parkFee;
}
/**
* Mutator for taxtFee
* @param taxiFee
*/
public void setTaxiFee(double taxiFee) {
this.taxiFee = taxiFee;
}
/**
* Mutator for regFee
* @param regFee
*/
public void setRegFee(double regFee) {
this.regFee = regFee;
}
/**
* Mutator for lodging
* @param lodging
*/
public void setLodging(double lodging) {
this.lodging = lodging;
}
/**
* This method calculates the Total Expense that the business person spent overall
* @return
*/
public double calcExpenseTotal() {
//Create variables for the Method
double totalExpense = 0.0;
double spentMeals = (days * DAILY_MEAL);
totalExpense = airfare + spentMeals + carRentalFee + parkFee + taxiFee + (lodging * days) + regFee + (miles * MILE_DRIVE);
this.setMeals(spentMeals);
return totalExpense;
}
/**
* This calculates the allowed Total expense that the company will cover for the trip
* The Allowable expense also includes Registration fee Rental Fee and AirFare cost
* @return
*/
public double calcAllowablExpense() {
//Create varaibles needed for method
double allowablExpense = 0.0;
if(lodging != 0) {
allowablExpense += (days * DAILY_LODGE);
}
if(parkFee != 0) {
allowablExpense += (days * DAILY_PARK);
}
if(taxiFee != 0) {
allowablExpense += (days * DAILY_TAXI);
}
if(miles != 0) {
allowablExpense += (miles * MILE_DRIVE);
}
if(regFee != 0) {
allowablExpense += regFee;
}
if(carRentalFee != 0) {
allowablExpense += carRentalFee;
}
if(airfare != 0) {
allowablExpense += airfare;
}
allowablExpense += (days * DAILY_MEAL);
return allowablExpense;
}
/**
* This method is used to calculate either what the busniessperson owes, or the amount that they saved, dependant on the sign of the calculated value
* @return
*/
public double calcOwed() {
//Create variables for the method
double owed = 0.0;
owed = this.calcExpenseTotal() - this.calcAllowablExpense();
return owed;
}
/**
* This is a method that will display all calculated totals
*/
public void displayMethod() {
//Create a variable to store the amount that is either owed or saved
double owed = this.calcOwed();
System.out.printf("Total Spent: $%.2f\n", this.calcExpenseTotal());
System.out.printf("Total Allowable: $%.2f\n", this.calcAllowablExpense());
if(owed >= 0.0) {
System.out.printf("Expense Amount: $%.2f\n", owed);
}
else {
owed = Math.abs(owed);
System.out.printf("Amount Saved: $%.2f\n", owed);
}
}
}