-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicket.java
More file actions
77 lines (68 loc) · 1.72 KB
/
Ticket.java
File metadata and controls
77 lines (68 loc) · 1.72 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
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
import java.util.Comparator;
import java.util.Random;
/**
*
*/
public class Ticket
{
private int id;
private Price price;
/**
* Constructor for a default ticket
*/
Ticket()
{
id = 0;
price = new Price(0, "$");
}
/**
* Constructor for a ticket given the id and generating its price randomly in US $
*
* @param i Id for the ticket
*/
public Ticket(int i)
{
this.id = i;
Random random = new Random();
price = new Price(random.nextInt(200) + 10, "$");
}
/**
* Constructor for a ticket given the id, value and currency
*
* @param i Id of the ticket
* @param value Price of the ticket
* @param currency Currency of the ticket
*/
public Ticket(int i, int value, String currency)
{
this.id = i;
price = new Price(value, currency);
}
/**
* Returns the price object for the ticket
*
* @return Price object for the ticket
*/
public Price getPrice()
{
return price;
}
/**
* Comparator for Collections.sort sorting tickets ArrayList in ascending order based on ticket price
*/
public static Comparator<Ticket> ticketComparatorAsc = (o1, o2) ->
{
int price1 = o1.getPrice().getValue();
int price2 = o2.getPrice().getValue();
return price1 - price2;
};
/**
* Comparator for Collections.sort sorting tickets ArrayList in descending order based on ticket price
*/
public static Comparator<Ticket> ticketComparatorDesc = (o1, o2) ->
{
int price1 = o1.getPrice().getValue();
int price2 = o2.getPrice().getValue();
return price2 - price1;
};
}