From 04b079a35921fcddfffb5abb131341e817219fe8 Mon Sep 17 00:00:00 2001 From: Orange_Dugongo Date: Mon, 10 Oct 2016 23:34:30 +0200 Subject: [PATCH] Esercizio3 --- src/Esercizio3.class | Bin 0 -> 1934 bytes src/Esercizio3.java | 66 +++++++++++++++++++++++++++++++++ src/RettangoloDaTastiera.class | Bin 1370 -> 1382 bytes src/RettangoloDaTastiera.java | 36 +++++++++--------- 4 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 src/Esercizio3.class create mode 100644 src/Esercizio3.java diff --git a/src/Esercizio3.class b/src/Esercizio3.class new file mode 100644 index 0000000000000000000000000000000000000000..c27a251c6452d628b8787cb32ded5c0a77685437 GIT binary patch literal 1934 zcma)7OHUhD6#g!L%y=@`U>*S)!Zc}ujREIXr?nGOASO&}48?gt(l&z`nSt?)H6FKw zRaI4$x~h~#5nW`PO%`nyfPz}7U9?iw{*wNLN=?rl%%eP_jy&g{d+xd4J@=gNjDP>< zvpeUgmgAz_4$;AaOE(*95!ev~M5Ww49ONqED;T^myAkB>#?skof>k>|3h>IIs zyeDE6gH*6ET&*GM^o!n_9L~bv4&e3@W!9Npz+RB2)FGD3&%38H* zlqq={<`~W$ax+Y2w`z4~s@`EgO4x2icR;CNdo^Nc+KYB_Zjso-&~ik@8N`zA-ZSRi z1&@|Di7aFo*NxHwZSj*%Y2OD{cwBY$GD8C=QQJ0!3_Gb>m6}T|(zSAip`*^+0}Gt= zKD$P^dmE>SczYXLyr^m0J~M+*;Z7z$unxSh3Pf7+u=HhDwFsG7OQm^CrN?VBy1{*F zJ*`sFt$BulqYw^tLcO$fl~XY_{+eacwYPhRp*42cF@rbhGto`o9?*A$@unfE(5#zA z#;tuDU_X$;$Q1~BMn6KF!K5o>8z*Z6ji(d8qO)%u4fOh!5~R@UTUvdJfd9GgIe9dA z7-9HG7tjTf4wvv2&HQNSqSEr_cpYkS2eo(%YM4+XgxdTcRBE(3>JUGP&TFMuBNV5f z0R6{cwV?^^h@xW$tBFV0i`X_6`;+c1QDXYo1k1Cu-+*3n5G2bY6k_eGk!B8M z+C?18=*Q<6z!wLazu^ f5)c>AxBFxC2uJ|U%}tGw^Wneokc!&xg*WgoF8!>L literal 0 HcmV?d00001 diff --git a/src/Esercizio3.java b/src/Esercizio3.java new file mode 100644 index 0000000..c9365fa --- /dev/null +++ b/src/Esercizio3.java @@ -0,0 +1,66 @@ +import java.awt.Rectangle; +import java.util.Scanner; + +public class Esercizio3{ + + public static boolean area(Rectangle r, Rectangle max){ + if(max==null || r.getWidth()*r.getHeight() > max.getWidth()*max.getHeight()) + return true; + + return false; + } + + public static boolean perimetro(Rectangle r, Rectangle max){ + if(max==null || r.getWidth()+r.getHeight() > max.getWidth()+max.getHeight()) + return true; + + return false; + } + + public static boolean posizione(Rectangle r, Rectangle max){ + if(max==null || r.getY() > max.getY()) + return true; + + return false; + } + + public static void main(String[] arg){ + + Rectangle ret, perimetroMax=null, areaMax=null, posMax=null; + int i=0, iPerimetro=0, iArea=0, iPosizione=0; + Scanner in = new Scanner(System.in); + + System.out.println("Inserisci la x, la y, la larghezza e l'altezza: "); + ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); + + while((ret.getX()!=0 || ret.getY()!=0) && (ret.getWidth()!=0 || ret.getHeight()!=0)){ + i++; + + if(perimetro(ret, perimetroMax)){ + perimetroMax=ret; + iPerimetro=i; + } + + if(area(ret, areaMax)){ + areaMax=ret; + iArea=i; + } + + if(posizione(ret, posMax)){ + posMax=ret; + iPosizione=i; + } + + System.out.println("Inserisci la x, la y, la larghezza e l'altezza: "); + ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); + } + + if(areaMax==null) + System.out.println("IMPOSSIBILE ESEGUIRE L'OPERAZIONE.\nSono stati inseriti zero rettangoli"); + else{ + System.out.println("Il "+iArea+"° rettangolo ha l'area massima"); + System.out.println("Il "+iPerimetro+"° rettangolo ha il perimetro massimo"); + System.out.println("Il "+iPosizione+"° rettangolo ha la posizione massima"); + } + } +} diff --git a/src/RettangoloDaTastiera.class b/src/RettangoloDaTastiera.class index 291df554a8726696bf1c719326ec4a50f22034f6..396a810b8d356553be3db5de5e546099efd88287 100644 GIT binary patch delta 51 zcmcb`^^9x7R7PPpPu~Fl;9yTDPajtW*I-xoP|wNB858*A4{cB=N-Zf#%uCPD$=}Sy H6u=As#`zIJ delta 39 vcmaFHb&G4mR7N3JPu~Fl;9yTDPajtW*I-xo(8((p6PQH~ZP+Zv6u=As33LpO diff --git a/src/RettangoloDaTastiera.java b/src/RettangoloDaTastiera.java index 2c1b912..0378da4 100644 --- a/src/RettangoloDaTastiera.java +++ b/src/RettangoloDaTastiera.java @@ -4,26 +4,26 @@ import java.util.Scanner; public class RettangoloDaTastiera{ public static void main(String[] arg){ - Rectangle ret, retMax=null; - int i=0, imax=0; - Scanner in = new Scanner(System.in); + Rectangle ret, retMax=null; + int i=0, imax=0; + Scanner in = new Scanner(System.in); - System.out.println("Inserisci la x, la y, la larghezza e l'altezza: "); - ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); - - while(ret.getX()!=0 || ret.getY()!=0 || ret.getWidth()!=0 || ret.getHeight()!=0){ - i++; - if(retMax==null || ret.getWidth()*ret.getHeight()>retMax.getWidth()*retMax.getHeight()){ - retMax=ret; - imax=i; - } System.out.println("Inserisci la x, la y, la larghezza e l'altezza: "); - ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); - } + ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); - if(retMax==null) - System.out.println("IMPOSSIBILE ESEGURE L'OPERAZIONE.\nSono stati inseriti zero rettangoli"); - else - System.out.println("Il "+imax+"° ha l'area massima"); + while(ret.getX()!=0 || ret.getY()!=0 || ret.getWidth()!=0 || ret.getHeight()!=0){ + i++; + if(retMax==null || ret.getWidth()*ret.getHeight()>retMax.getWidth()*retMax.getHeight()){ + retMax=ret; + imax=i; + } + System.out.println("Inserisci la x, la y, la larghezza e l'altezza: "); + ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); + } + + if(retMax==null) + System.out.println("IMPOSSIBILE ESEGUIRE L'OPERAZIONE.\nSono stati inseriti zero rettangoli"); + else + System.out.println("Il "+imax+"° rettangolo ha l'area massima"); } }