-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathDiscountBill.java
More file actions
32 lines (25 loc) · 964 Bytes
/
DiscountBill.java
File metadata and controls
32 lines (25 loc) · 964 Bytes
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
package com.example.task02;
public class DiscountBill extends Bill{
private double discountPercentage;
public DiscountBill(double discountPercentage){
setDiscountPercentage(discountPercentage);
}
public void setDiscountPercentage(double discountPercentage){
if (discountPercentage < 0 || discountPercentage > 100){
throw new IllegalArgumentException("Скидка должна быть в диапазона от 1 до 100");
}
this.discountPercentage = discountPercentage;
}
public double getDiscountPercentage(){
return discountPercentage;
}
public long getDiscountAbsolute(){
long originalPrice = super.getPrice();
return Math.round(originalPrice * discountPercentage / 100);
}
public long getPrice(){
long originalPrice = super.getPrice();
long discount = getDiscountAbsolute();
return originalPrice - discount;
}
}