// This program reads in some Circles and Rectangle Objects
// from a file into a HashSet and then prints them out.
//
// In data file there is either a 1 or a 2 separating the
// objects. If 1 it is a circle and has a radius after it.
// If 2 it is a rectangle and so has a width and height
// after it.
//
// by www.neiljohan.com

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.FileReader;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

public class FigureProg
{
    static Set FigureSet = new HashSet();
    
    public static void main(String[] pArgs) throws IOException
        {
            int tType = 0;
            double tRadius = 0;
            double tWidth = 0;
            double tHeight = 0;
            Figure tCircle = new Circle();
            Figure tRectangle = new Rectangle();

            final BufferedReader tInputHandle = new BufferedReader(new FileReader("data.dat"));
            String tLine = "NotNull";
            
            while (tLine!=null)
            {
                tLine = tInputHandle.readLine();
                if (tLine==null)
                {
                    break;
                }
                else{
                    tType = new Integer(tLine).intValue();
                    if (tType == 1){
                        //It is a circle
                        tRadius = new Double(tInputHandle.readLine()).doubleValue();
                        tCircle = new Circle(tRadius);
                        FigureSet.add(tCircle);
                    }
                    else if (tType == 2){
                        //It is a quadrilateral
                        tWidth = new Double(tInputHandle.readLine()).doubleValue();
                        tHeight = new Double(tInputHandle.readLine()).doubleValue();
                        tRectangle = new Rectangle(tWidth,tHeight);
                        FigureSet.add(tRectangle);
                    }
                }
            }

            final Iterator tIterator = FigureSet.iterator();
            Figure tFigure;
            
            while (tIterator.hasNext()){
                Object pObject = tIterator.next();
                tFigure = (Figure)pObject;
                System.out.println(tFigure + " " + tFigure.area() + " " + tFigure.perimeter());
            }
        }
}













