-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarRental.java
More file actions
45 lines (40 loc) · 1.19 KB
/
CarRental.java
File metadata and controls
45 lines (40 loc) · 1.19 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
package lesson3;
public final class CarRental {
private final String carModel;
private final double days;
private final double ratePerDay;
private final double milesPerday;
public CarRental(String carModel, double days, double ratePerDay, double milesPerday){
this.carModel=carModel;
this.days=days;
this.ratePerDay=ratePerDay;
this.milesPerday=milesPerday;
if(days<=0){
throw new IllegalArgumentException("Days Must be Positive");
}
if(ratePerDay<=0){
throw new IllegalArgumentException("ratePerDay Must be Positive");
}
if(milesPerday<=0){
throw new IllegalArgumentException("milePerDay Must be Positive");
}
}
public String getCarModel() {
return carModel;
}
public double getDays() {
return days;
}
public double getRatePerDays() {
return ratePerDay;
}
public double getMilesPerday() {
return milesPerday;
}
public double totalRentalCost(){
return days*ratePerDay;
}
public double totalMilesAllowed(){
return days*milesPerday;
}
}