From 681e0f73a7fba2cbe1ae656ebcb622ad429a1542 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 7 Nov 2016 18:41:36 +0100 Subject: [PATCH] Nuovi filtri --- src/FigureGeometriche/Manager.java | 30 ++++++++++++++++++++++++++++++ src/FigureGeometriche/Test.java | 7 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/FigureGeometriche/Manager.java b/src/FigureGeometriche/Manager.java index ffd6347..71dc6e0 100644 --- a/src/FigureGeometriche/Manager.java +++ b/src/FigureGeometriche/Manager.java @@ -36,6 +36,36 @@ public class Manager{ return max; } + + public FiguraGeometrica getAreaMin() { + FiguraGeometrica min = figure.get(0); + + for (int i = 1; i < figure.size(); i++) + if (min.calcolaArea() > figure.get(i).calcolaArea()) + min = figure.get(i); + + return min; + } + + public FiguraGeometrica getPerimetroMax(){ + FiguraGeometrica max = figure.get(0); + + for (int i = 1; i < figure.size(); i++) + if (max.calcolaPerimetro() < figure.get(i).calcolaPerimetro()) + max = figure.get(i); + + return max; + } + + public FiguraGeometrica getPerimetroMin(){ + FiguraGeometrica min = figure.get(0); + + for (int i = 1; i < figure.size(); i++) + if (min.calcolaPerimetro() > figure.get(i).calcolaPerimetro()) + min = figure.get(i); + + return min; + } public void print(PrintStream ps){ for(FiguraGeometrica fg: figure) diff --git a/src/FigureGeometriche/Test.java b/src/FigureGeometriche/Test.java index c49ae7a..ce12e95 100644 --- a/src/FigureGeometriche/Test.java +++ b/src/FigureGeometriche/Test.java @@ -1,11 +1,16 @@ import java.io.File; import java.util.Scanner; +import java.io.PrintStream; public class Test { public static void main(String [] args) throws Exception{ Scanner sc = new Scanner(new File("figure")); Manager manager = new Manager(sc); + PrintStream ps = System.out; - manager.getAreaMax().print(System.out); + ps.println("Figura con area maggiore"); + manager.getAreaMax().print(ps); + ps.println("Figura con perimetro minore"); + manager.getPerimetroMin().print(System.out); } }