From f22fb9811aeed5cc8f9cb3256fe27e30e32dd938 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Mon, 14 Mar 2022 17:26:22 +0100 Subject: [PATCH] TP08 Polymorphisme --- APL2.1/TP08/Moyenne/Moyenne.class | Bin 0 -> 482 bytes APL2.1/TP08/Moyenne/Moyenne.java | 18 ++++++++ APL2.1/TP08/Moyenne/TestMoyenne.class | Bin 0 -> 737 bytes APL2.1/TP08/Moyenne/TestMoyenne.java | 12 ++++++ APL2.1/TP08/Polyligne/Etoile.class | Bin 0 -> 791 bytes APL2.1/TP08/Polyligne/Etoile.java | 26 ++++++++++++ APL2.1/TP08/Polyligne/Polyligne.class | Bin 0 -> 1263 bytes APL2.1/TP08/Polyligne/Polyligne.java | 39 ++++++++++++++++++ .../TP08/Polyligne/ProducteurDePoints.class | Bin 0 -> 156 bytes APL2.1/TP08/Polyligne/ProducteurDePoints.java | 5 +++ APL2.1/TP08/Polyligne/Spirale.class | Bin 0 -> 861 bytes APL2.1/TP08/Polyligne/Spirale.java | 34 +++++++++++++++ APL2.1/TP08/Polyligne/Test.class | Bin 0 -> 724 bytes APL2.1/TP08/Polyligne/Test.java | 20 +++++++++ APL2.1/TP08/Véhicules/Moto.class | Bin 0 -> 261 bytes APL2.1/TP08/Véhicules/Moto.java | 6 +++ APL2.1/TP08/Véhicules/Vehicule.class | Bin 0 -> 400 bytes APL2.1/TP08/Véhicules/Vehicule.java | 12 ++++++ APL2.1/TP08/Véhicules/Vehicules.class | Bin 0 -> 1407 bytes APL2.1/TP08/Véhicules/Vehicules.java | 22 ++++++++++ APL2.1/TP08/Véhicules/Voiture.class | Bin 0 -> 267 bytes APL2.1/TP08/Véhicules/Voiture.java | 6 +++ 22 files changed, 200 insertions(+) create mode 100644 APL2.1/TP08/Moyenne/Moyenne.class create mode 100644 APL2.1/TP08/Moyenne/Moyenne.java create mode 100644 APL2.1/TP08/Moyenne/TestMoyenne.class create mode 100644 APL2.1/TP08/Moyenne/TestMoyenne.java create mode 100644 APL2.1/TP08/Polyligne/Etoile.class create mode 100644 APL2.1/TP08/Polyligne/Etoile.java create mode 100644 APL2.1/TP08/Polyligne/Polyligne.class create mode 100644 APL2.1/TP08/Polyligne/Polyligne.java create mode 100644 APL2.1/TP08/Polyligne/ProducteurDePoints.class create mode 100644 APL2.1/TP08/Polyligne/ProducteurDePoints.java create mode 100644 APL2.1/TP08/Polyligne/Spirale.class create mode 100644 APL2.1/TP08/Polyligne/Spirale.java create mode 100644 APL2.1/TP08/Polyligne/Test.class create mode 100644 APL2.1/TP08/Polyligne/Test.java create mode 100644 APL2.1/TP08/Véhicules/Moto.class create mode 100644 APL2.1/TP08/Véhicules/Moto.java create mode 100644 APL2.1/TP08/Véhicules/Vehicule.class create mode 100644 APL2.1/TP08/Véhicules/Vehicule.java create mode 100644 APL2.1/TP08/Véhicules/Vehicules.class create mode 100644 APL2.1/TP08/Véhicules/Vehicules.java create mode 100644 APL2.1/TP08/Véhicules/Voiture.class create mode 100644 APL2.1/TP08/Véhicules/Voiture.java diff --git a/APL2.1/TP08/Moyenne/Moyenne.class b/APL2.1/TP08/Moyenne/Moyenne.class new file mode 100644 index 0000000000000000000000000000000000000000..59150536477ab5f15f2aee25d319d13d203950d7 GIT binary patch literal 482 zcmY*VO-sW-6r4@cq)lU6tF`qLikCKmJ$O)11W^Q`>Om=ZGfkF~(k4)wg1^9@BZ5`% z;1BReiL*^XCG6~bZ{C}Eo3HPWPXPPavSFf=20I6h{n(d-Bqr*R+!itR9xSIMv|N4H*gz>4k#fk36v?t2rjHSnTdE9DQ> znB9}(lZhO8J=NN1QrNzUlaVjaLpAMO#*Z?JILe@bJwuKD`n2GI3WvDBY;TqWMfV-T)u+(h z!W8-oDS-m941<^>xK|2{^qn^t{y(Jxtw3v==2e;t gEK)sPW1IRyu`Wk>w5Rx)X}W?rqmR7Sh-~q=&?W}S%^!L6w)PeR*4tXvgQ!GZJ>wR@jX|#m{ys)DMt_L`bM4lN2O@kg$AAUvy|YL#A&~cK!m^ zCbD;{iHgz0AK(0H#cxIqVoW-4c?>qP2bI*HUe}DP{U>36`ZsstIN){PZGYcck z@-ty)=D$z;TyIQ{WEPCE`tHGxZzgJ)g^d>pAP0e4v6;*vkEz(yP24tdN5Fi(sC*qN z0pSP?E(U&2OJ8ruPNdSTZV|HAhYW;rFYpO%2;`;zq@x;YM}}IUkVKB}hN{bc0vSK* zsxY84=lPy~D3GpHHw28upv7Uursu1bsJo@Yb-C4H#_UDjE+-2NSE|izxhw1PnXaz} zp06K}*_xJads*%r!*gpv6uN53i)-_bbU1TSrvmvEZ@QIv6p{#h!V!a2qx|HbE->z`Zn$48fbj?~pFT zczJ;NGR&hW+jgDL$ZwWmRX(E7-am4R?fpZPnzd4^)cSxSdy}O_mqTCUR5HBwhCNfs vbeof74k;8dh!VLEp+g=S)v*a)mfn~*NEhXzu=h28>DzWX>;QbTt$t2 literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Polyligne/Etoile.java b/APL2.1/TP08/Polyligne/Etoile.java new file mode 100644 index 0000000..bad5e8f --- /dev/null +++ b/APL2.1/TP08/Polyligne/Etoile.java @@ -0,0 +1,26 @@ +import java.awt.Point; + +public class Etoile implements ProducteurDePoints { + private static final int xCentre = 100; + private static final int yCentre = 100; + private static final double rayon = 90.0; + private static final double angleDepart = Math.PI/4.0; + private static final double angleIncrement = (4.0*Math.PI)/5.0; + private double numero; + public Etoile() { + this.numero = 0.0; + } + public Point suivant() { + Point p = null; + if (this.numero < 6.0) { + double angle = Etoile.angleDepart+this.numero*Etoile.angleIncrement; + p = new Point((int) (Etoile.rayon*Math.cos(angle)), + (int) (Etoile.rayon*Math.sin(angle))); + p.translate(Etoile.xCentre, Etoile.yCentre); + this.numero++; + } else { + this.numero = 0.0; + } + return p; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Polyligne.class b/APL2.1/TP08/Polyligne/Polyligne.class new file mode 100644 index 0000000000000000000000000000000000000000..d6173d6bc5b04557f2437d12fe9a6009dba323da GIT binary patch literal 1263 zcmZuxOH&g;5dJ0sHVH!n0^<7tK0=5_d<#B_fM|e75D=ehvWC@UH*PipcYlH&ym{lS zC9(8idD1F>k2fv#n~ee~P1SZ!_jLF4_f1c}{`~L}z$x4dp%eRq=)i#xx^XbXRaA*y zWyaL1Pl>oP4+U`;i6D-kKY*hl9K&&yc_N6DIHkmCWu8%?1I-x3Sqd$=d$7Lml@D>*0fBQ6}qDT3+SB@Xh_;Q zLtskkU_giAV4N!rDdZ5fs;usOQk!KkB`7R+pUP?c!OxO(>SxL)!y zHCzw~W$cQRHAYOYQra#o7tFk6999q{w&SA2R&0~FgdvF}E=vq!L}C)W^`$om6*d#iFqZqpiAPGO1&*{2X_U6YYh;E zYGEl+UNo(I;_3!?ZEN)Y1t;K-Dtt{@$Ix9;(i!dj4+R1NvpiYSpHvvajCnGWH{2m| zl6UNil@n;+n3%K+w!_N_lnv6$wLoM8wY6<^Zh%#0&78a7l^r7vI<6RIeu1|UcxV<1 zQ%06cEjq@Z$_TGv_*1xXD0L}$t!{Y!9^dN47Ie~(SuVRqk*C-dmg}rxH0?y%;RIw{ zqA#-Fh?h|B=HVq3RIn5~wZvLUm+rhb9_vkcb15K}_z{j+CXAe;FRIxiN&k*8%a<$W zQ(cW;9f!3SfW3S#oqULXejEf!sO$GM=Zo40!ExI`xsz6mwvRd#dj}EgTZQj6ErDH> zVXsOv8Xyrw3-xa7`IGkzjo$8yzAF6Vu__u~Vr!hbv5Ka+-_MoCFHl7={stjB-=Mi& zR?!lBi|}U*#g%@GO*Pd@)mF2pTB~S}DbFgxO8ed;BCv`!<@@sM(+c)%bl1nM{CcGz z_&f*$1Oc?M*$6>&c;s}GkX}Bvev)vSB+N1LKA{x}Zjt{q&(MSCI6x|)K>t9uhVJlp M3@grhywdxA1L{E+-2eap literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Polyligne/Polyligne.java b/APL2.1/TP08/Polyligne/Polyligne.java new file mode 100644 index 0000000..6862197 --- /dev/null +++ b/APL2.1/TP08/Polyligne/Polyligne.java @@ -0,0 +1,39 @@ +import java.awt.*; +import javax.swing.*; + +public class Polyligne extends JComponent { + Point p1; + Point p2; + + ProducteurDePoints pp; + + public Polyligne(ProducteurDePoints arg) { + super(); + pp = arg; + } + + @Override + protected void paintComponent(Graphics brush) { + Graphics newBrush = brush.create(); + + if (this.isOpaque()) { + newBrush.setColor(this.getBackground()); + newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + newBrush.setColor(Color.BLACK); + System.out.println("Test"); + + while (true) { + if (p1 != null) { + newBrush.drawLine(p1.x, p1.y, p2.x, p2.y); + p1 = p2; + p2 = pp.suivant(); + if (p2 == null) break; + } else { + p1 = pp.suivant(); + p2 = pp.suivant(); + } + } + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/ProducteurDePoints.class b/APL2.1/TP08/Polyligne/ProducteurDePoints.class new file mode 100644 index 0000000000000000000000000000000000000000..d02e0502669a13029c294c71ad6a30ef3d754167 GIT binary patch literal 156 zcmX^0Z`VEs1_pBmPId-%b_Nbc2KM68%(BG15=I6g4Nae{#Ii*F#PSmTfc(t75^F{V zuHgLAqU2P!%$!t42JwKR{FKtH7XjS*gh- eY>W(y3`{`#85kH@7#WxuSU@ZWRv^j5zy<))*eAUJ literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Polyligne/ProducteurDePoints.java b/APL2.1/TP08/Polyligne/ProducteurDePoints.java new file mode 100644 index 0000000..4c0dd33 --- /dev/null +++ b/APL2.1/TP08/Polyligne/ProducteurDePoints.java @@ -0,0 +1,5 @@ +import java.awt.Point; + +public interface ProducteurDePoints { + Point suivant(); +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Spirale.class b/APL2.1/TP08/Polyligne/Spirale.class new file mode 100644 index 0000000000000000000000000000000000000000..91a58d7e6897f16ed662cf0260825dcd747c9ce7 GIT binary patch literal 861 zcmZ8gO-~b16g{tB)7EJzSQYRSQS66MzYq|kCRCFqtq?Ipmao$n9Vj!+bOvMG_zT<_ zqYHn7CL)T7?p?U^M;MoGjq$tzYvW9E=broSJNMlC-hBDJ^9jHV<_(n67)05?*%YFf zOx##`!WBTHsl@f2uit+@{_!pG`NIqSyfjcrL*Se?=hHB8L7R&PE*Y2>Ff8Txp1LO> zY66)B*XjDw@mFL!P*JkBdMT>{aZf&S9i~{mh(621Hw&TxJ|FSQw^@i;1rKgwOz_ZjXTkkcOJGLj=YD#aTu5fpo zVk!;kKQJ+dlPs{8Wa2nROq{^T-^^Ye6PGb#Vpf|m%$c}?If2|iy2a+2vb4k{&us;k zuL7^CLWx~AXt}hpLbb>tM!Po0886goy6cqhNvGSEz9MgwhfE42F^c`j(?7s*MsSe$ z(0_OsBfa%F*GKzsn&@yJK0 0.0) { + p = new Point( + (int)(Math.cos(angle) * curRadius), + (int)(Math.sin(angle) * curRadius) + ); + + p.translate(centreX, centreY); + } + + return p; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Test.class b/APL2.1/TP08/Polyligne/Test.class new file mode 100644 index 0000000000000000000000000000000000000000..de326229142934288c3fc8c35c6574b59e960bee GIT binary patch literal 724 zcmYjP-EPw`7(H&%rp>bTXRwWpF$M$Drd?qOaWMoJ9g{Y?t*BGc;L2@G<*7}oBxQ{E z;6b=aB`Wa%JO~fL1>$pxR3hv6^YQWbozL;lKi_`=46W|un*dc$`GL%u0JaXKD$MR3l$ z17h?cmmb54{h@iuKk@p2d;NMl3Z&QHR|n0uKMs20P%3fmT!hiC(pe~BnW3cO&-L(% z0SABwY)2>xy9cB0QIJ-_zH zlx@SF^~$fJ`iwi_9`B1F>3G#{wgTTB_aZS44n)hBUKA!f8h2fW%73RD{&3`b!i)CH z^OSRvu8+!gWGH8MZND#fu#E!!X!WH)H;84z8?@S_nbDlCOu)WTz;Kf=laM-cSivgA zO8ONVbei8zk-C^bYdS^zrV>3U0xTk#;gMG7gJjOpzr`?qmw{qB_CCX|0G~G-6ma zO^dPU)M6~XbMzSbdD%T!N%1TU@<@-43~bR;+abP+MLfe2ULlXy)Xf`Gw30s7=u8T? F{sJB+lqLWG literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Polyligne/Test.java b/APL2.1/TP08/Polyligne/Test.java new file mode 100644 index 0000000..474e9da --- /dev/null +++ b/APL2.1/TP08/Polyligne/Test.java @@ -0,0 +1,20 @@ +import java.awt.*; +import javax.swing.*; + +public class Test { + public static void main(String[] args) { + JFrame f = new JFrame(); + f.setSize(250, 250); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setLayout(null); + + Spirale e = new Spirale(); + Polyligne pl = new Polyligne(e); + pl.setSize(230, 230); + pl.setLocation(0, 0); + f.add(pl); + + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Moto.class b/APL2.1/TP08/Véhicules/Moto.class new file mode 100644 index 0000000000000000000000000000000000000000..c833b93ec1772c473fa93d19384c436c41464052 GIT binary patch literal 261 zcmW-b%}T>i6okK+N8nt_OnuXm6E)+L~g3xwT={{{Q?Uk5FOcWo>MG;*106vs> zZZ~tz3^T+0{(b)dHwOnm1 z$BSs$#D<4uQEi6vwlUS_mUEfq%Ulqvtrd)fUE|0H{rn4+_jWjW=I-!5_s&=_!xMA_ OT}gPP(xf=pYso*@C@TX1 literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Véhicules/Moto.java b/APL2.1/TP08/Véhicules/Moto.java new file mode 100644 index 0000000..ad240e1 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Moto.java @@ -0,0 +1,6 @@ +public class Moto extends Vehicule { + public Moto() { + this.wheels = 2; + this.type = "Moto"; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Vehicule.class b/APL2.1/TP08/Véhicules/Vehicule.class new file mode 100644 index 0000000000000000000000000000000000000000..4a7c2aae6c09a37dc47d496dfb50833df2819347 GIT binary patch literal 400 zcmZvX%}T>i5QWd=w~f)(TK^U<+_f&+r3=N4AP7alO7}^;w70}W(nRr{T(lqvE_?tV zN<3E(v2-(M?#y@Q&U}8oe*iefegGHkIvi}9u;XLb$DY7@nkbdd1ac{G%I60qXbq;( zW7JQhY}_A~h0ew&1W$FQ%QJ!9>5hn==XXRK1D&a>>ONM*Z4{@h_*s0DSBet}a;7`W zi<0$rr@LxwFwCnWQ5V{H*GFoilPXm`vp|RdYau-NA!?`#YQJqk^KZlJc&d`pIpkF? zPqnDDFmsHHYD3H<#*nWAs!-jdH^_nszh(4(il()J2IGJ971qlVY79+mu0ZYi5*iR{ Iv1VcG8_&Q$r~m)} literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Véhicules/Vehicule.java b/APL2.1/TP08/Véhicules/Vehicule.java new file mode 100644 index 0000000..d8635e7 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Vehicule.java @@ -0,0 +1,12 @@ +public abstract class Vehicule { + protected int wheels; + protected String type; + + public int nbRoues() { + return this.wheels; + } + + public String sorte() { + return this.type; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Vehicules.class b/APL2.1/TP08/Véhicules/Vehicules.class new file mode 100644 index 0000000000000000000000000000000000000000..33dadc7f35b670feedd889847629e83b34b6f838 GIT binary patch literal 1407 zcmaJ>+j0{}5IrNwn)Q0ILAFB(*vP~L35*5dj=%&&j720&A~5C3(^#Ie7O!ShyCXa1 zOMo9pcuXFEf`S*`@==f;X@NDUqN<%sPxt9F-AD89`&VxPT)?u66b^Ib9n3g5;^2D+ zvm8fVaQwhA<6_tzA8|2)!^1d+f{Q~a+TnPP5awN!aEjwJL-vZVe6zriE)-W7G8Mfp z8OCb9l6Si8H5uL$YXMm@ZQ(11ZwkNH9*Qkd3WVAyHB9KMjj|2g(=ejBSr?t2KgW+8 zXE@F>xDDM6n{v^&D5EQ~4z79l3D-Gpc&Oke!|*5m4CBd4^m&)R zu*UTvY9He$Q`FMieMUEZ5$FvDQ|Q-JY@1R=w>w%%Wy*;<$LI-5j9jhuY#(o0ZE95> zKr0a#LlvvL%HG(CjBJw#beD=h+4uK#=`QuxP%bIjbhn{MhlW}*Q79%5KV6cmwcj+g zpr@s(i=VMbow%=Lp5;3_ir)RTZkM6;nWvMs*pwBmn!-HrO^a5M5z0{bvA7;dja3Jx z9PcS-H&GH#$I=c+2a^MkiYpwqY+rw2nEk9gUv2448B4lPYf&_f4tF@}^gpR-z1i(B zcvYojSP2AakGMWgW{5HR5?T^!orFHy4@|Z*u2`amy8`d+bmRc{0ewx@B!;MnAZYkT zmO1V)9R2EkgSatF|Gyt*kfRsJ{!$=~V}iy>+D*~SXdXKL0_<;E&I=BFKQZzeBee8t z|6tFF=NP4L>=pI`&#}*DOZBo%)2nB5j!}jwI-S8j%n`}6MDrHqK0v1jk$O)?j_=q9 l8Z#URIS$z^9i}PFf=%N#%`OpMLJd_4JVASh_H*=|{0}Y)Z~g!P literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Véhicules/Vehicules.java b/APL2.1/TP08/Véhicules/Vehicules.java new file mode 100644 index 0000000..e27de37 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Vehicules.java @@ -0,0 +1,22 @@ +import javax.swing.JOptionPane; + +public class Vehicules { + public static void main(String[] args) { + Vehicule v; + Object[] choix = {"Voiture", "Moto"}; + + int reponse = JOptionPane.showOptionDialog(null, + "Quel v\u00E9hicule choisissez-vous ?", + "Question", + JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + choix, + null); + if (reponse == 0) + v = new Voiture(); + else + v = new Moto(); + System.out.println("Une "+v.sorte()+" poss\u00E8de "+v.nbRoues()+" roues."); + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Voiture.class b/APL2.1/TP08/Véhicules/Voiture.class new file mode 100644 index 0000000000000000000000000000000000000000..0e8f32161a5c896535f1eb80aa8bf55865860b1e GIT binary patch literal 267 zcmXYry-veG5QM+8jn6R$4(6w)0~e%0q6ngigoG5)1i5#@DLG_pWNZ+RMG+xU@Blm% z$~vN%-I?8)-QU0OAK;3Un2@~zJM2d!eI05N&4D7kc9m;y6#m(Ht_UXeqg5nRSK0gS zd2XABVqS_8&+4vO*jv{Vlh>~88hi0nycGsbWJozw=>LJ?h+{>R+m%~%y(N5KSzEp; z)SX;uKVC#jr@env7S(bzYa3TB$DGP@p*#(;+9wMRgk9oE2gB?OmFYEJmilXg&+TR` Tm=Xwjg1$Hc5=m0*ZZ)$30wpb} literal 0 HcmV?d00001 diff --git a/APL2.1/TP08/Véhicules/Voiture.java b/APL2.1/TP08/Véhicules/Voiture.java new file mode 100644 index 0000000..7db37a6 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Voiture.java @@ -0,0 +1,6 @@ +public class Voiture extends Vehicule { + public Voiture() { + this.wheels = 4; + this.type = "Voiture"; + } +} \ No newline at end of file