-
Notifications
You must be signed in to change notification settings - Fork 0
/
Promo.java
41 lines (34 loc) · 753 Bytes
/
Promo.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
package project;
public class Promo{
private int ID;
private int type;
private int amount;
public Promo(int id, int t, int a){
ID = id;
type = t;
amount = a;
}
public double findPrice(double price){
if(type == 1)
price *= (1-amount/100.0);
else if(type==2 && price<=amount)
price = 0;
else if(type == 2)
price -= amount;
return (Math.round(price*100))/100.0;
}
public int getID(){
return ID;
}
public String getInfo(){
return (ID + ",\t" + type + ",\t" + amount);
}
public String toString(){
if(type == 1)
return (amount + "% off");
else if(type == 2)
return ("$" + amount + " off");
else
return "Invalid promo code";
}
}