-
Notifications
You must be signed in to change notification settings - Fork 0
/
Article.java
130 lines (114 loc) · 4.62 KB
/
Article.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Article.java
*
* Created on 9 vril 2007
*
* uthor BRUN Joel & DEBONNEL Yann
*/
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Vector;
public class Article implements java.io.Serializable {
public int id;
private static int ids = 1;
private String nom;
private float prixBase;
public float bestMise;
public String leader;
private Vector<Mise> mises;
private GregorianCalendar timeFin;
private String stTimeFin;
private boolean isTimeOut;
private String timeRemaining;
private String timeServeur;
private String month[] = {"janvier","fevrier","mars","avril","mai",
"juin","juillet","aout","septembre","octobre","novembre","decembre"};
private DateFormat dateTimeFormat=DateFormat.getDateTimeInstance();
private DateFormat timeFormat= DateFormat.getTimeInstance();
public Article(String nom, double prix, String time_fin){
this.id=ids++;
this.nom = nom;
this.prixBase = (float) prix;
this.bestMise = (float) prix;
this.leader = "";
this.mises = new Vector<Mise>();
this.timeFin = new GregorianCalendar();
timeFin.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time_fin.substring(0,2)));
timeFin.set(Calendar.MINUTE, Integer.parseInt(time_fin.substring(3,5)));
//timeFin.set(Calendar.SECOND, Integer.parseInt(time_fin.substring(3,5)));
timeFin.set(Calendar.SECOND,0);
String stToday = timeFin.get(Calendar.DAY_OF_MONTH)+" "+
month[timeFin.get(Calendar.MONTH)]+" "+
timeFin.get(Calendar.YEAR)+", ";
stTimeFin="";
int a = timeFin.get(Calendar.HOUR_OF_DAY);
if(a<10) stTimeFin+="0"+a+":"; else stTimeFin+=a+":";
a = timeFin.get(Calendar.MINUTE);
if(a<10) stTimeFin+="0"+a+":"; else stTimeFin+=a+":";
a = timeFin.get(Calendar.SECOND);
if(a<10) stTimeFin+="0"+a; else stTimeFin+=a;
System.out.println(" fin: "+stToday+stTimeFin);
GregorianCalendar now = new GregorianCalendar();
if(timeFin.before(now)) {isTimeOut = true; }
else isTimeOut = false;
System.out.println(" fin: "+isTimeOut);
}
public synchronized boolean addMise(String client, float montant){
if(!IsTimeOut() && montant>bestMise){
leader = client;
bestMise = montant;
Mise uneMise = new Mise(client, montant);
mises.add(uneMise);
setTimeRemaining();
return true;
} else return false;
}
public boolean IsTimeOut(){
return isTimeOut;
}
public String getNom(){ return nom;}
public float getPrix(){ return prixBase;}
public float getbestMise(){ return bestMise;}
public String getLeader(){ return leader;}
public String getDateFin(){ return stTimeFin;}
public String getHeureServeur(){ return timeServeur;}
public String getTimeRemaining(){return timeRemaining;}
public void setTimeRemaining(){
timeRemaining = timeFormat.format(new Date(timeFin.getTimeInMillis() - (new GregorianCalendar()).getTimeInMillis()));
GregorianCalendar now = new GregorianCalendar();
if(timeFin.before(now)) isTimeOut = true;
else isTimeOut = false;
int a = now.get(Calendar.HOUR_OF_DAY);
if(a<10) timeServeur+="0"+a+":"; else timeServeur+=a+":";
a = now.get(Calendar.MINUTE);
if(a<10) timeServeur+="0"+a+":"; else timeServeur+=a+":";
a = now.get(Calendar.SECOND);
if(a<10) timeServeur+="0"+a; else timeServeur+=a;
}
public void print(){
int i=1;String st;
if(mises.size()==0) return;
Iterator ite = mises.iterator();
for (; ite.hasNext() && i<mises.size(); ){
st="|mise "+ i +": ";
System.out.println(st);
Mise uneMise = (Mise) ite.next();
int len = 60-st.length() - uneMise.print();
st="";
for (int j=len; j>0; j--) {st+=" ";}
st+="|";
System.out.println(st);
i++;
}
st="|derniere mise ";
Mise uneMise = (Mise) ite.next();
int len = 50-st.length() - uneMise.print();
for (int j=len; j>0; j--) {st+=" ";}
st+="|";
System.out.println(st);
}
}