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
|
public class Achat
{
private int clientId;
private int articleId;
private int prix;
ArrayList<Achat> data;
public Achat(int clientId, int articleId, int prix)
{
this.clientId = clientId;
this.articleId = articleId;
this.prix = prix;
}
public Achat() {
}
public int getClientId(){return clientId;}
public int getArticleId(){return articleId;}
public int getPrix(){return prix;}
public ArrayList<Achat> ParseFile() throws IOException
{
BufferedReader reader = new BufferedReader(new FileReader("C:\file.txt"));
String line;
ArrayList<Achat> items = new ArrayList<Achat>();
StringTokenizer splitter;
while ((line = reader.readLine()) != null)
{
splitter = new StringTokenizer(line, " ");
if (splitter.hasMoreTokens()) {
clientId = Integer.parseInt(splitter.nextToken());;
articleId = Integer.parseInt(splitter.nextToken());
prix = Integer.parseInt(splitter.nextToken());
items.add(new Achat(clientId,articleId,prix)); }
}
return items;
}
public int getArticlesCount() {
//Achat test = new Achat();
//Ici j'ai unhandled exception file IO Exception
data = ParseFile();
int TotalItems = 0;
ArrayList <Integer> v = new ArrayList <Integer> ();
for (int i = 0; i < data.size(); i++)
{
v.add(i);
TotalItems = Math.max(TotalItems,v.size());
}
return TotalItems;
}
} |