Created
March 22, 2025 11:03
-
-
Save trikitrok/46d550810ab90651e2988b805a50e2e9 to your computer and use it in GitHub Desktop.
Used to illustrate Feature sketches and Effect Sketches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Reservation { | |
private duration: number; | |
private dailyRate: number; | |
private readonly date: Date; | |
private readonly customer: Customer; | |
private readonly fees: FeeRider[]; | |
constructor(customer: Customer, duration: number, dailyRate: number, date: Date) { | |
this.fees = []; | |
this.customer = customer; | |
this.duration = duration; | |
this.dailyRate = dailyRate; | |
this.date = date; | |
} | |
public extend(additionalDays: number): void { | |
this.duration += additionalDays; | |
} | |
public extendForWeek(): void { | |
const weekRemainder = RentalCalendar.weekRemainderFor(this.date); | |
const DAYS_PER_WEEK = 7; | |
this.extend(weekRemainder); | |
this.dailyRate = RateCalculator.computeWeekly(this.customer.getRateCode()) / DAYS_PER_WEEK; | |
} | |
public addFee(rider: FeeRider): void { | |
this.fees.push(rider); | |
} | |
public getTotalFee(): number { | |
return this.getPrincipalFee() + this.getAdditionalFees(); | |
} | |
private getAdditionalFees(): number { | |
let total = 0; | |
for (const fee of this.fees) { | |
total += fee.getAmount(); | |
} | |
return total; | |
} | |
private getPrincipalFee(): number { | |
return this.dailyRate * RateCalculator.rateBase(this.customer) * this.duration; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment