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,13 +5,17 @@ import java.util.Scanner;
public class Manager{
public Manager(Scanner sc) throws Exception{
figure = new ArrayList<FiguraGeometrica>();
FiguraGeometrica fg;
String tipo=sc.next();
FiguraGeometrica fg=read(sc);
while(fg!=null){
figure.add(fg);
fg=read(sc);
}
}
do{
if(!sc.hasNext())
fg=null;
else{
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);
@ -19,19 +23,18 @@ public class Manager{
fg=Rettangolo.read(sc);
else
fg=Cerchio.read(sc);
figure.add(fg);
}
}while(fg!=null);
return fg;
}
public double getAreaMax() {
public FiguraGeometrica getAreaMax() {
FiguraGeometrica max = figure.get(0);
for (int i = 1; i < figure.size(); i++)
if (max.calcolaArea() < figure.get(i).calcolaArea())
max = figure.get(i);
return max.calcolaArea();
return max;
}
public void print(PrintStream ps){

View File

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

View File

@ -1,6 +1,6 @@
Cerchio 2
Regolare 2 0.5 4
Regolare 2 1.03 7
Rettangolo 3 5
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