-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDutchAuctionTuple.java
More file actions
76 lines (68 loc) · 3.29 KB
/
DutchAuctionTuple.java
File metadata and controls
76 lines (68 loc) · 3.29 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
import lights.*;
import lights.interfaces.*;
public class DutchAuctionTuple extends AuctionTuple {
// private String oggettoAsta;
// private String venditore;
// private Double offertaMinima;
public static final int SECONDS_TO_WAIT_DUTCH = 10; // secondi da aspettare fino ad abbassare il prezzo
public Double decrementoPerc;
public Double offertaIniziale;
public int secondiDecremento;
public Double offertaAttuale;
public DutchAuctionTuple(String oggettoAsta, String venditore, Double offertaMinima, Double offertaIniziale,Double decrementoPerc, int secondiDecremento, Double offertaAttuale) {
super(oggettoAsta, venditore, offertaMinima);
this.decrementoPerc = decrementoPerc;
this.offertaIniziale = offertaIniziale;
this.secondiDecremento = secondiDecremento;
this.offertaAttuale = offertaAttuale;
if (offertaAttuale == null){
this.offertaAttuale = offertaIniziale;
}
}
public void decrementa(){
this.offertaAttuale = Math.round((this.offertaAttuale - this.offertaIniziale*this.decrementoPerc)*100.0)/100.0;
}
public static ITuple getTemplateTypes() {
return new Tuple()
.add(new Field().setType(String.class))
.add(new Field().setType(String.class))
.add(new Field().setType(Double.class))
.add(new Field().setType(Double.class))
.add(new Field().setType(Double.class))
.add(new Field().setType(Integer.class))
.add(new Field().setType(Double.class));
}
public ITuple getTuple() {
return new Tuple()
.add(new Field().setValue(this.oggettoAsta))
.add(new Field().setValue(this.venditore))
.add(new Field().setValue(this.offertaMinima))
.add(new Field().setValue(this.offertaIniziale))
.add(new Field().setValue(this.decrementoPerc))
.add(new Field().setValue(this.secondiDecremento))
.add(new Field().setValue(this.offertaAttuale));
}
//SAME AS AUCTIONTUPLE
// //template to get all the offers for this auction
// public ITuple getTemplateOffers() {
// return new Tuple()
// .add(new Field().setValue(this.oggettoAsta))
// .add(new Field().setValue(this.venditore))
// .add(new Field().setType(String.class)) //acquirente
// .add(new Field().setType(Double.class)); //offerta
// }
public static DutchAuctionTuple fromTuple(ITuple tuple) {
return new DutchAuctionTuple(
(String)( (Field) tuple.get(0)).getValue(),
(String) ( (Field) tuple.get(1)).getValue(),
(Double) ( (Field) tuple.get(2)).getValue(),
(Double) ( (Field) tuple.get(3)).getValue(),
(Double) ( (Field) tuple.get(4)).getValue(),
(int) ( (Field) tuple.get(5)).getValue(),
(Double) ( (Field) tuple.get(6)).getValue()
);
}
public void print() {
System.out.println("Item for sale : " + this.oggettoAsta + " sold by " + this.venditore + " at the minimum price of " + this.offertaMinima + " with a decrement of " + this.decrementoPerc + "% every " + this.secondiDecremento + " seconds" + " and an initial price of " + this.offertaIniziale + " and an actual price of " + this.offertaAttuale);
}
}