import java.io.*;
/**
 * Write a description of class MercatoFrutta here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MercatoFrutta
{
    private static PartitaFrutta leggiPartitaFrutta(BufferedReader r) throws IOException{
        String frutta, peso, giorni, prezzo;
        frutta=r.readLine();
        if (frutta==null)
            return null;
        peso=r.readLine();
        giorni=r.readLine();
        prezzo=r.readLine();
 /*       System.out.println
        	(val+ " " + ser +" " + prs +" " + dis);
*/
        float pkg=Float.parseFloat(peso);
        int gg=Integer.parseInt(giorni);
        float pr=Float.parseFloat(prezzo);
        PartitaFrutta f1 = new PartitaFrutta(frutta,pkg,gg);
        f1.setPrezzo(false,pr);
        return f1;
    }
    
    public static PartitaFrutta[] leggi(String filename) throws IOException{
        FileReader f=new FileReader(filename);
        BufferedReader r=new BufferedReader(f);
        PartitaFrutta d=null;
        //conta quanti blocchi nel file
        int count =0;
        do{
            d=leggiPartitaFrutta(r);
            if (d!=null) count++;
        }while (d!=null);
        if (count == 0)
            return null;
        PartitaFrutta [] vec=new PartitaFrutta[count];
        f=new FileReader(filename);
        r=new BufferedReader(f);
        count =0;
        do{
            d=leggiPartitaFrutta(r);
            if (d!=null) {
                vec[count]=d;
                count++;
            }
        }while (d!=null);
        return vec;
    }   

}
