This commit is contained in:
Orange 2016-11-07 18:31:04 +01:00
parent e03e128d70
commit 89723b37fa
3 changed files with 26 additions and 24 deletions

View File

@ -5,33 +5,36 @@ import java.util.Scanner;
public class Manager{ public class Manager{
public Manager(Scanner sc) throws Exception{ public Manager(Scanner sc) throws Exception{
figure = new ArrayList<FiguraGeometrica>(); figure = new ArrayList<FiguraGeometrica>();
FiguraGeometrica fg; FiguraGeometrica fg=read(sc);
String tipo=sc.next(); while(fg!=null){
do{
if(!sc.hasNext())
fg=null;
else{
tipo=sc.next();
if(tipo.equals("Regolare"))
fg=FiguraRegolare.read(sc);
else if(tipo.equals("Rettangolo"))
fg=Rettangolo.read(sc);
else
fg=Cerchio.read(sc);
figure.add(fg); figure.add(fg);
} fg=read(sc);
}while(fg!=null); }
}
private static FiguraGeometrica read(Scanner sc) throws Exception{
FiguraGeometrica fg;
String tipo;
if(!sc.hasNext()) return null;
tipo=sc.next();
if(tipo.equals("Regolare"))
fg=FiguraRegolare.read(sc);
else if(tipo.equals("Rettangolo"))
fg=Rettangolo.read(sc);
else
fg=Cerchio.read(sc);
return fg;
} }
public double getAreaMax() { public FiguraGeometrica getAreaMax() {
FiguraGeometrica max = figure.get(0); FiguraGeometrica max = figure.get(0);
for (int i = 1; i < figure.size(); i++) for (int i = 1; i < figure.size(); i++)
if (max.calcolaArea() < figure.get(i).calcolaArea()) if (max.calcolaArea() < figure.get(i).calcolaArea())
max = figure.get(i); max = figure.get(i);
return max.calcolaArea(); return max;
} }
public void print(PrintStream ps){ public void print(PrintStream ps){

View File

@ -6,7 +6,6 @@ public class Test {
Scanner sc = new Scanner(new File("figure")); Scanner sc = new Scanner(new File("figure"));
Manager manager = new Manager(sc); Manager manager = new Manager(sc);
//manager.getAreaMax(); manager.getAreaMax().print(System.out);
manager.print(System.out);
} }
} }

View File

@ -1,6 +1,6 @@
Cerchio 2 Cerchio 2
Regolare 2 0.5 4
Regolare 2 1.03 7
Rettangolo 3 5
Cerchio 3 Cerchio 3
Regolare 2 2.35 15 Regolare 2 1,03 7
Rettangolo 3 5
Regolare 2 0,5 4
Regolare 2 2,35 15