-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bill.java
104 lines (76 loc) · 3.22 KB
/
Bill.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
*Bill Class. TCSS 305 - Rentz
*/
package model;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;
import model.vehicles.AbstractVehicle;
/**
* @author hphobbs
* @version Winter 2020
*/
public class Bill {
/** * Displays an amount fashioned on the US currency system. */
public static final NumberFormat NF = NumberFormat.getCurrencyInstance(Locale.US);
/** * A unique integer value. */
private final int myBillID;
/** * A User object. */
private final User myPrimaryUser;
/** * A Vehicle object. */
private final AbstractVehicle myVehicle;
/** * An integer representing the number of days Vehicle is rented. */
private final int myNumDays;
/** * Total bill amount. */
private BigDecimal myBillAmount;
/**
* Parameterized constructor for the Bill class. Initializes relevant instance fields. *
*
* @param theBillID A unique integer value assigned to the bill.
* @param thePrimaryUser A User object.
* @param theVehicle A Vehicle object.
* @param theNumDays An integer representing the number of days Vehicle is rented.
*/
public Bill(final int theBillID, final User thePrimaryUser,
final AbstractVehicle theVehicle, final int theNumDays) {
this.myBillID = theBillID;
this.myPrimaryUser = thePrimaryUser;
this.myVehicle = theVehicle;
this.myNumDays = theNumDays;
this.myBillAmount = new BigDecimal("0.0");
}
/**
* * Computes and prints the total bill amount.
*
* @param theOutput
*/
public void computeAndPrintAmount(final PrintStream theOutput) {
theOutput.println("----Cost Information----");
theOutput.println("RentalPerDay:");
final BigDecimal calculateRent = myVehicle.calculateRentalAmount();
theOutput.println("Cost per Day: " + NF.format(calculateRent));
theOutput.println("No.of Rental days: " + myNumDays);
final BigDecimal numOfDays = new BigDecimal(myNumDays);
final BigDecimal totalAmountBefore = calculateRent.multiply(numOfDays);
theOutput.println("Total Amount: " + NF.format(totalAmountBefore));
final BigDecimal onePercentRate = new BigDecimal("0.01");
final BigDecimal insurance = totalAmountBefore.multiply(onePercentRate);
theOutput.println("Insurance: " + NF.format(insurance));
BigDecimal vipStatus = new BigDecimal("0.00");
if (myPrimaryUser.getMyVIPStatus()) {
vipStatus = totalAmountBefore.multiply(onePercentRate);
theOutput.println("VIPDiscount: -" + NF.format(vipStatus));
} else {
theOutput.println("VIPDiscount: " + NF.format(vipStatus));
}
final BigDecimal tax = totalAmountBefore.multiply(new BigDecimal("0.1"));
theOutput.println("Tax: " + NF.format(tax));
myBillAmount = totalAmountBefore.add(insurance).subtract(vipStatus).add(tax);
theOutput.println("Total Rent: " + NF.format(myBillAmount));
}
/** @return myBillID */
public int getBillID() {
return myBillID;
}
}