Initial commit
This commit is contained in:
commit
ac16299bf9
51 changed files with 819 additions and 0 deletions
11
initiationJava/.classpath
Normal file
11
initiationJava/.classpath
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/home/romainv/Documents/INSA/java/itextpdf-5.5.7.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
initiationJava/.project
Normal file
17
initiationJava/.project
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>initiationJava</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
14
initiationJava/.settings/org.eclipse.jdt.core.prefs
Normal file
14
initiationJava/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,14 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
6
initiationJava/bin/.gitignore
vendored
Normal file
6
initiationJava/bin/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
/Exercice11.class
|
||||
/Exercice21.class
|
||||
/Partie3/
|
||||
/Partie5/
|
||||
/partie4/
|
||||
/partie6/
|
BIN
initiationJava/fichier1.pdf
Normal file
BIN
initiationJava/fichier1.pdf
Normal file
Binary file not shown.
1
initiationJava/infos.txt
Normal file
1
initiationJava/infos.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Première ligne du fichier
|
BIN
initiationJava/rendu_infos.txt
Normal file
BIN
initiationJava/rendu_infos.txt
Normal file
Binary file not shown.
BIN
initiationJava/src/Exercice11.class
Normal file
BIN
initiationJava/src/Exercice11.class
Normal file
Binary file not shown.
5
initiationJava/src/Exercice11.java
Normal file
5
initiationJava/src/Exercice11.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
public class Exercice11 {
|
||||
public static void main (String[] argv) {
|
||||
System.out.println("Ola, mon Premier de Programme");
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Exercice21.class
Normal file
BIN
initiationJava/src/Exercice21.class
Normal file
Binary file not shown.
18
initiationJava/src/Exercice21.java
Normal file
18
initiationJava/src/Exercice21.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
public class Exercice21 {
|
||||
public static void main(String[] argv) {
|
||||
final int[] monTabInt= {1,2,3,4,5};
|
||||
char[] monTabChar= {'a','b','c','d','e'};
|
||||
afficheTableau(monTabInt,monTabChar);
|
||||
}
|
||||
public static void afficheTableau(int[] tab1, char[] tab2) {
|
||||
for (int current1 : tab1){
|
||||
System.out.println(current1);
|
||||
}
|
||||
for (int current2 : tab2){
|
||||
System.out.println((char)current2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
BIN
initiationJava/src/Partie3/Exercice21.class
Normal file
BIN
initiationJava/src/Partie3/Exercice21.class
Normal file
Binary file not shown.
BIN
initiationJava/src/Partie3/Exercice31.class
Normal file
BIN
initiationJava/src/Partie3/Exercice31.class
Normal file
Binary file not shown.
14
initiationJava/src/Partie3/Exercice31.java
Normal file
14
initiationJava/src/Partie3/Exercice31.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package Partie3;
|
||||
|
||||
public class Exercice31 {
|
||||
public static void main(String[] argv) {
|
||||
Voiture jaguar = new Voiture();
|
||||
Voiture renaud = new Voiture();
|
||||
Class c=Voiture.class;
|
||||
System.out.println(c.getSuperclass());
|
||||
jaguar.vitesse=250;
|
||||
jaguar.puissance=12;
|
||||
renaud.vitesse=250;
|
||||
renaud.puissance=12;
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Exercice33.class
Normal file
BIN
initiationJava/src/Partie3/Exercice33.class
Normal file
Binary file not shown.
23
initiationJava/src/Partie3/Exercice33.java
Normal file
23
initiationJava/src/Partie3/Exercice33.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package Partie3;
|
||||
|
||||
public class Exercice33 {
|
||||
public static void main(String[] argv) {
|
||||
Voiture3 voiture1 = new Voiture3();
|
||||
Voiture3 voiture2 = new Voiture3();
|
||||
voiture1.setPuissance(150);
|
||||
voiture1.setVitesse(45);
|
||||
voiture1.demarre();
|
||||
voiture2.setPuissance(150);
|
||||
voiture2.setVitesse(45);
|
||||
voiture2.demarre("VROOOOOOOOOOOOOOOOOOOOOOM");
|
||||
System.out.println(voiture1);
|
||||
System.out.println(voiture2);
|
||||
System.out.println(voiture1.getClass());
|
||||
//Pour tester le type on peut faire :
|
||||
System.out.println(voiture1 instanceof Voiture3);
|
||||
voiture1=null;
|
||||
voiture2=null;
|
||||
System.out.println(voiture2);
|
||||
System.gc();
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Exercice34.class
Normal file
BIN
initiationJava/src/Partie3/Exercice34.class
Normal file
Binary file not shown.
22
initiationJava/src/Partie3/Exercice34.java
Normal file
22
initiationJava/src/Partie3/Exercice34.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package Partie3;
|
||||
|
||||
|
||||
public class Exercice34 {
|
||||
public static void main(String[] argv){
|
||||
Voiture34 voiture1 = new Voiture34();
|
||||
Voiture34 voiture2 = new Voiture34();
|
||||
voiture1.setNom('y');
|
||||
voiture2.setNom('z');
|
||||
System.out.println(Voiture34.nombreDeVoitures());
|
||||
int i=0;
|
||||
while(Voiture34.getListeVoitures()[i]!=null) {
|
||||
System.out.println("Voiture n° " + i + " : " +
|
||||
(char)Voiture34.getListeVoitures()[i].getNom()); //Je ne sais pas pourquoi on a besoin de caster mais ça renvoie le code ascii sinon
|
||||
i++;
|
||||
}
|
||||
for(int y=0;y<Voiture34.getListeVoitures2().size();y++) {
|
||||
System.out.println("Voiture n° " + i + " : " +
|
||||
(char)Voiture34.getListeVoitures2().get(y).getNom());
|
||||
}
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Exerice32.class
Normal file
BIN
initiationJava/src/Partie3/Exerice32.class
Normal file
Binary file not shown.
15
initiationJava/src/Partie3/Exerice32.java
Normal file
15
initiationJava/src/Partie3/Exerice32.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package Partie3;
|
||||
|
||||
public class Exerice32 {
|
||||
public static void main(String[] argv) {
|
||||
Voiture2 maCaisse = new Voiture2();
|
||||
maCaisse.setPuissance(150);
|
||||
maCaisse.setVitesse(45);
|
||||
maCaisse.demarre();
|
||||
System.out.println(maCaisse.getVitesse());
|
||||
System.out.println(maCaisse.getPuissance());
|
||||
System.out.println(maCaisse.getEstDemarre());
|
||||
|
||||
}
|
||||
|
||||
}
|
BIN
initiationJava/src/Partie3/Voiture.class
Normal file
BIN
initiationJava/src/Partie3/Voiture.class
Normal file
Binary file not shown.
19
initiationJava/src/Partie3/Voiture.java
Normal file
19
initiationJava/src/Partie3/Voiture.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package Partie3;
|
||||
|
||||
public class Voiture {
|
||||
public int puissance;
|
||||
public int vitesse;
|
||||
public boolean estDemarre;
|
||||
|
||||
public Voiture() {
|
||||
puissance=0;
|
||||
vitesse=0;
|
||||
estDemarre=false;
|
||||
}
|
||||
|
||||
public Voiture(int pu,int vi,boolean estDem) {
|
||||
puissance=pu;
|
||||
vitesse=vi;
|
||||
estDemarre=estDem;
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Voiture2.class
Normal file
BIN
initiationJava/src/Partie3/Voiture2.class
Normal file
Binary file not shown.
29
initiationJava/src/Partie3/Voiture2.java
Normal file
29
initiationJava/src/Partie3/Voiture2.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package Partie3;
|
||||
|
||||
public class Voiture2 {
|
||||
private int puissance;
|
||||
private int vitesse;
|
||||
private boolean estDemarre;
|
||||
|
||||
public int getPuissance() {
|
||||
return puissance;
|
||||
}
|
||||
public int getVitesse() {
|
||||
return vitesse;
|
||||
}
|
||||
public boolean getEstDemarre() {
|
||||
return estDemarre;
|
||||
}
|
||||
public void setPuissance(int pui) {
|
||||
puissance=pui;
|
||||
}
|
||||
public void setVitesse(int vit) {
|
||||
vitesse=vit;
|
||||
}
|
||||
public void setEstDemarre(boolean estDem) {
|
||||
estDemarre=estDem;
|
||||
}
|
||||
public void demarre() {
|
||||
estDemarre=true;
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Voiture3.class
Normal file
BIN
initiationJava/src/Partie3/Voiture3.class
Normal file
Binary file not shown.
33
initiationJava/src/Partie3/Voiture3.java
Normal file
33
initiationJava/src/Partie3/Voiture3.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package Partie3;
|
||||
|
||||
public class Voiture3 {
|
||||
private int puissance;
|
||||
private int vitesse;
|
||||
private boolean estDemarre;
|
||||
|
||||
public int getPuissance() {
|
||||
return puissance;
|
||||
}
|
||||
public int getVitesse() {
|
||||
return vitesse;
|
||||
}
|
||||
public boolean getEstDemarre() {
|
||||
return estDemarre;
|
||||
}
|
||||
public void setPuissance(int pui) {
|
||||
puissance=pui;
|
||||
}
|
||||
public void setVitesse(int vit) {
|
||||
vitesse=vit;
|
||||
}
|
||||
public void setEstDemarre(boolean estDem) {
|
||||
estDemarre=estDem;
|
||||
}
|
||||
public void demarre() {
|
||||
estDemarre=true;
|
||||
}
|
||||
public void demarre(String message) {
|
||||
estDemarre=true;
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
BIN
initiationJava/src/Partie3/Voiture34.class
Normal file
BIN
initiationJava/src/Partie3/Voiture34.class
Normal file
Binary file not shown.
77
initiationJava/src/Partie3/Voiture34.java
Normal file
77
initiationJava/src/Partie3/Voiture34.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package Partie3;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Voiture34 {
|
||||
|
||||
//Varirables privées
|
||||
|
||||
private int puissance;
|
||||
private int vitesse;
|
||||
private boolean estDemarre;
|
||||
private char nom;
|
||||
private static int nbVoitures=0;
|
||||
private static Voiture34[] listeVoitures = new Voiture34[10];
|
||||
private static ArrayList<Voiture34> listeVoitures2 = new ArrayList<Voiture34>();
|
||||
|
||||
//Constructeurs
|
||||
|
||||
public Voiture34() {
|
||||
listeVoitures[nbVoitures]=this;
|
||||
listeVoitures2.add(this);
|
||||
nbVoitures++;
|
||||
}
|
||||
|
||||
//Assesseurs
|
||||
|
||||
public int getPuissance() {
|
||||
return puissance;
|
||||
}
|
||||
public int getVitesse() {
|
||||
return vitesse;
|
||||
}
|
||||
public boolean getEstDemarre() {
|
||||
return estDemarre;
|
||||
}
|
||||
public int getNom() {
|
||||
return nom;
|
||||
}
|
||||
public void setPuissance(int pui) {
|
||||
puissance=pui;
|
||||
}
|
||||
public void setVitesse(int vit) {
|
||||
vitesse=vit;
|
||||
}
|
||||
public void setEstDemarre(boolean estDem) {
|
||||
estDemarre=estDem;
|
||||
}
|
||||
public void setNom(char n) {
|
||||
nom=n;
|
||||
}
|
||||
|
||||
//Méthodes
|
||||
|
||||
public void demarre() {
|
||||
estDemarre=true;
|
||||
}
|
||||
public void demarre(String message) {
|
||||
estDemarre=true;
|
||||
System.out.println(message);
|
||||
}
|
||||
public static int nombreDeVoitures() {
|
||||
return nbVoitures;
|
||||
}
|
||||
public static Voiture34[] getListeVoitures() {
|
||||
return listeVoitures;
|
||||
}
|
||||
public static ArrayList<Voiture34> getListeVoitures2() {
|
||||
return listeVoitures2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
31
initiationJava/src/Partie5/Avion.java
Normal file
31
initiationJava/src/Partie5/Avion.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package Partie5;
|
||||
|
||||
public class Avion {
|
||||
public long vitesse;
|
||||
public long puissance;
|
||||
|
||||
public Avion() {
|
||||
vitesse=0;
|
||||
puissance=0;
|
||||
}
|
||||
|
||||
public Avion(long vit, long puis) {
|
||||
vitesse=vit;
|
||||
puissance=puis;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
Avion avionic=new Avion();
|
||||
if(o instanceof Avion) {
|
||||
avionic=(Avion) o;
|
||||
if(vitesse==avionic.vitesse && puissance==avionic.puissance){
|
||||
return true;
|
||||
}
|
||||
else{ return false; }
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
initiationJava/src/Partie5/AvionElectrique.java
Normal file
12
initiationJava/src/Partie5/AvionElectrique.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package Partie5;
|
||||
|
||||
public class AvionElectrique extends Avion {
|
||||
|
||||
public AvionElectrique(){
|
||||
super();
|
||||
}
|
||||
|
||||
public AvionElectrique(long vit, long puis) {
|
||||
super(vit, puis);
|
||||
}
|
||||
}
|
17
initiationJava/src/Partie5/Carre.java
Normal file
17
initiationJava/src/Partie5/Carre.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package Partie5;
|
||||
|
||||
public class Carre extends Forme {
|
||||
private double cote;
|
||||
|
||||
public Carre(double ct) {
|
||||
cote=ct;
|
||||
}
|
||||
|
||||
public double perimetre() {
|
||||
return cote*4;
|
||||
}
|
||||
|
||||
public double surface() {
|
||||
return Math.pow(cote, 2);
|
||||
}
|
||||
}
|
18
initiationJava/src/Partie5/Cercle.java
Normal file
18
initiationJava/src/Partie5/Cercle.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package Partie5;
|
||||
|
||||
public class Cercle extends Forme {
|
||||
private double rayon;
|
||||
|
||||
public Cercle(double ray) {
|
||||
rayon=ray;
|
||||
}
|
||||
|
||||
public double perimetre() {
|
||||
return rayon*2.0*3.14;
|
||||
}
|
||||
|
||||
public double surface() {
|
||||
return Math.pow(rayon, 2)*3.14;
|
||||
}
|
||||
}
|
||||
|
10
initiationJava/src/Partie5/Forme.java
Normal file
10
initiationJava/src/Partie5/Forme.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package Partie5;
|
||||
|
||||
public abstract class Forme {
|
||||
public abstract double perimetre();
|
||||
public abstract double surface();
|
||||
public double etalement() {
|
||||
double peri=perimetre();
|
||||
return 16*surface()/Math.pow(peri, 2);
|
||||
}
|
||||
}
|
11
initiationJava/src/Partie5/Test.java
Normal file
11
initiationJava/src/Partie5/Test.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package Partie5;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] argv) {
|
||||
Cercle cercle = new Cercle(4);
|
||||
Carre carre = new Carre(8);
|
||||
System.out.println("Etalement du cercle : " + cercle.etalement());
|
||||
System.out.println("Etalement du carre : " + carre.etalement());
|
||||
|
||||
}
|
||||
}
|
14
initiationJava/src/Partie5/TestAvion.java
Normal file
14
initiationJava/src/Partie5/TestAvion.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package Partie5;
|
||||
|
||||
public class TestAvion {
|
||||
public static void main(String[] argv){
|
||||
Avion avion1 = new Avion(12,59999);
|
||||
AvionElectrique avion2 = new AvionElectrique(12,59999);
|
||||
Avion avion3 = new Avion(12,5999569);
|
||||
System.out.println(avion1.equals(avion2));
|
||||
System.out.println(avion1.equals(avion3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
20
initiationJava/src/partie4/Exercice41.java
Normal file
20
initiationJava/src/partie4/Exercice41.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package partie4;
|
||||
|
||||
import Partie3.Voiture;
|
||||
|
||||
public class Exercice41 {
|
||||
public static void main(String[] argv) {
|
||||
VehiculePrioritaire ambulance = new VehiculePrioritaire();
|
||||
VehiculePrioritaire fourgon = new VehiculePrioritaire();
|
||||
ambulance.allumeGyrophare();
|
||||
ambulance.accelere(3);
|
||||
fourgon.allumeGyrophare();
|
||||
fourgon.accelere(28);
|
||||
int nbVoit=VehiculePrioritaire.getNombreDeVoitures();
|
||||
System.out.println(nbVoit);
|
||||
long vitesseAmbulance=ambulance.getVitesse();
|
||||
long vitesseFourgon=fourgon.getVitesse();
|
||||
System.out.println("Vitesse de l'ambulance : " + vitesseAmbulance);
|
||||
System.out.println("Vitesse du fourgon : " + vitesseFourgon);
|
||||
}
|
||||
}
|
28
initiationJava/src/partie4/VehiculePrioritaire.java
Normal file
28
initiationJava/src/partie4/VehiculePrioritaire.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package partie4;
|
||||
|
||||
public class VehiculePrioritaire extends Voiture {
|
||||
|
||||
//---------------------------Variables privées : --------------------------------------------
|
||||
|
||||
private boolean gyrophare;
|
||||
|
||||
//---------------------------Méthodes de classe : -------------------------------------------
|
||||
|
||||
public VehiculePrioritaire() {
|
||||
super();
|
||||
gyrophare=false;
|
||||
}
|
||||
|
||||
public void allumeGyrophare(){
|
||||
if(gyrophare==false) {
|
||||
gyrophare=true;
|
||||
}
|
||||
super.accelere(5);
|
||||
}
|
||||
|
||||
/*
|
||||
public void accelere(int v) {
|
||||
vitesse+=2*v;
|
||||
}
|
||||
*/
|
||||
}
|
BIN
initiationJava/src/partie4/Voiture.class
Normal file
BIN
initiationJava/src/partie4/Voiture.class
Normal file
Binary file not shown.
83
initiationJava/src/partie4/Voiture.java
Normal file
83
initiationJava/src/partie4/Voiture.java
Normal file
|
@ -0,0 +1,83 @@
|
|||
package partie4;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Voiture {
|
||||
|
||||
//Variables privées
|
||||
|
||||
protected int puissance;
|
||||
protected long vitesse;
|
||||
protected boolean estDemarre;
|
||||
protected char nom;
|
||||
protected static int nbVoitures=0;
|
||||
protected static ArrayList<Voiture> listeVoitures2 = new ArrayList<Voiture>();
|
||||
public java.util.Date dateCreation = new java.util.Date();
|
||||
|
||||
//Constructeurs
|
||||
|
||||
public Voiture() {
|
||||
listeVoitures2.add(this);
|
||||
nbVoitures++;
|
||||
}
|
||||
|
||||
public Voiture(long vit) {
|
||||
vitesse=vit;
|
||||
listeVoitures2.add(this);
|
||||
nbVoitures++;
|
||||
}
|
||||
|
||||
public Voiture(long vit, java.util.Date date) {
|
||||
vitesse=vit;
|
||||
listeVoitures2.add(this);
|
||||
nbVoitures++;
|
||||
}
|
||||
|
||||
//Assesseurs
|
||||
|
||||
public int getPuissance() {
|
||||
return puissance;
|
||||
}
|
||||
public long getVitesse() {
|
||||
return vitesse;
|
||||
}
|
||||
public boolean getEstDemarre() {
|
||||
return estDemarre;
|
||||
}
|
||||
public int getNom() {
|
||||
return nom;
|
||||
}
|
||||
public void setPuissance(int pui) {
|
||||
puissance=pui;
|
||||
}
|
||||
public void setVitesse(int vit) {
|
||||
vitesse=vit;
|
||||
}
|
||||
public void setEstDemarre(boolean estDem) {
|
||||
estDemarre=estDem;
|
||||
}
|
||||
public void setNom(char n) {
|
||||
nom=n;
|
||||
}
|
||||
|
||||
//Méthodes
|
||||
|
||||
public void demarre() {
|
||||
estDemarre=true;
|
||||
}
|
||||
public void demarre(String message) {
|
||||
estDemarre=true;
|
||||
System.out.println(message);
|
||||
}
|
||||
public static int getNombreDeVoitures() {
|
||||
return nbVoitures;
|
||||
}
|
||||
public static ArrayList<Voiture> getListeVoitures2() {
|
||||
return listeVoitures2;
|
||||
}
|
||||
public void accelere(int v) {
|
||||
vitesse+=v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
29
initiationJava/src/partie6/ErrConst.java
Normal file
29
initiationJava/src/partie6/ErrConst.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package partie6;
|
||||
|
||||
public class ErrConst extends Exception{
|
||||
private String message = "Echec création";
|
||||
private int abs;
|
||||
private int ord;
|
||||
|
||||
public ErrConst() {
|
||||
}
|
||||
|
||||
public ErrConst(int x, int y) {
|
||||
abs=x;
|
||||
ord=y;
|
||||
}
|
||||
|
||||
public int getAbs() {
|
||||
return abs;
|
||||
}
|
||||
|
||||
public int getOrd() {
|
||||
return ord;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
28
initiationJava/src/partie6/ErrDepl.java
Normal file
28
initiationJava/src/partie6/ErrDepl.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package partie6;
|
||||
|
||||
public class ErrDepl extends Exception {
|
||||
private String message = "Erreur déplacement";
|
||||
private int dlAbs;
|
||||
private int dlOrd;
|
||||
|
||||
public ErrDepl() {
|
||||
}
|
||||
|
||||
public ErrDepl(int dx, int dy) {
|
||||
dlAbs = dx;
|
||||
dlOrd = dy;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getDlAbs() {
|
||||
return dlAbs;
|
||||
}
|
||||
|
||||
public int getDlOrd() {
|
||||
return dlOrd;
|
||||
}
|
||||
|
||||
}
|
BIN
initiationJava/src/partie6/Exercice61.class
Normal file
BIN
initiationJava/src/partie6/Exercice61.class
Normal file
Binary file not shown.
11
initiationJava/src/partie6/Exercice61.java
Normal file
11
initiationJava/src/partie6/Exercice61.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package partie6;
|
||||
import partie4.Voiture;
|
||||
|
||||
|
||||
public class Exercice61 {
|
||||
public static void main(String[] argv) {
|
||||
Voiture voiture = new Voiture(15);
|
||||
System.out.println(voiture.getVitesse());
|
||||
System.out.println(voiture.dateCreation);
|
||||
}
|
||||
}
|
24
initiationJava/src/partie6/Exercice62.java
Normal file
24
initiationJava/src/partie6/Exercice62.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package partie6;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
public class Exercice62 {
|
||||
public static void main(String[] args) {
|
||||
Document document = new Document();
|
||||
document.addAuthor("Romain Vitrat");
|
||||
document.addTitle("Le récit d'un grand héro");
|
||||
document.addCreationDate();
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream("fichier1.pdf");
|
||||
PdfWriter writer = PdfWriter.getInstance(document, fos);
|
||||
document.open();
|
||||
document.add(new Paragraph("Il était une fois, etc ..."));
|
||||
document.close();
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
21
initiationJava/src/partie6/Point.java
Normal file
21
initiationJava/src/partie6/Point.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package partie6;
|
||||
|
||||
public class Point {
|
||||
public int x; int y;
|
||||
public Point(int x, int y) throws ErrConst{
|
||||
if ((x<0) || (y<0)) throw new ErrConst(x,y);
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
}
|
||||
public void affiche() {
|
||||
System.out.println("Coordonnées : " + x + " " + y);
|
||||
}
|
||||
|
||||
public void deplace(int dx, int dy) throws ErrDepl {
|
||||
if (((x+dx) < 0) || ((y+dy) <0)) throw new ErrDepl(dx,dy);
|
||||
x += dx ;
|
||||
y +=dy;
|
||||
}
|
||||
|
||||
}
|
||||
|
38
initiationJava/src/partie6/Point2.java
Normal file
38
initiationJava/src/partie6/Point2.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package partie6;
|
||||
|
||||
public class Point2 {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public Point2(int xx, int yy) {
|
||||
x=xx;
|
||||
y=yy;
|
||||
}
|
||||
|
||||
public void affiche() {
|
||||
System.out.println(x);
|
||||
System.out.println(y);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public boolean equals(Object pp) {
|
||||
Point2 p = (Point2)pp;
|
||||
return ((this.x == p.x) && (this.y == p.y));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
34
initiationJava/src/partie6/TestHashMap.java
Normal file
34
initiationJava/src/partie6/TestHashMap.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package partie6;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class TestHashMap {
|
||||
public static void main(String[] argv) {
|
||||
Point2 p1 = new Point2(1,3);
|
||||
Point2 p2 = new Point2(2,2);
|
||||
Point2 p3 = new Point2(4,5);
|
||||
Point2 p4 = new Point2(1,3);
|
||||
|
||||
HashMap<Point2,Integer> hashMapPoints = new HashMap<Point2,Integer>();
|
||||
hashMapPoints.put(p1,5);
|
||||
hashMapPoints.put(p2,9);
|
||||
hashMapPoints.put(p3,10);
|
||||
System.out.println("clé : " + hashMapPoints.get(p1));
|
||||
System.out.println("Contains key : " + hashMapPoints.containsKey(p1));
|
||||
System.out.println("value 10 : " + hashMapPoints.containsValue(10));
|
||||
System.out.println(hashMapPoints.get(p4));
|
||||
affiche(hashMapPoints);
|
||||
System.out.println("Hashcode de p4 : " + p4.hashCode());
|
||||
System.out.println("p4 dans la collection : " + hashMapPoints.containsKey(p4));
|
||||
|
||||
}
|
||||
static public void affiche(HashMap<Point2,Integer> hmap) {
|
||||
Iterator<Point2> iter = hmap.keySet().iterator();
|
||||
while(iter.hasNext()) {
|
||||
Point2 p =iter.next();
|
||||
System.out.println("key : " + p.hashCode() + " value : " + hmap.get(p));
|
||||
}
|
||||
}
|
||||
}
|
15
initiationJava/src/partie6/TestIO.java
Normal file
15
initiationJava/src/partie6/TestIO.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package partie6;
|
||||
|
||||
import java.io.FileWriter;
|
||||
|
||||
public class TestIO {
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
FileWriter myFile = new FileWriter("infos.txt");
|
||||
myFile.write("Première ligne du fichier");
|
||||
myFile.close();
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
21
initiationJava/src/partie6/TestIO2.java
Normal file
21
initiationJava/src/partie6/TestIO2.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package partie6;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class TestIO2 {
|
||||
public static void main(String[] argv) {
|
||||
System.out.println("Veuillez saisir votre nom");
|
||||
String inputLine = " ";
|
||||
try {
|
||||
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
|
||||
inputLine = is.readLine();
|
||||
is.close();
|
||||
} catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
if (inputLine != null) {
|
||||
System.out.println("Votre nom est : " + inputLine);
|
||||
}
|
||||
}
|
||||
}
|
24
initiationJava/src/partie6/TestIO3.java
Normal file
24
initiationJava/src/partie6/TestIO3.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package partie6;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class TestIO3 {
|
||||
public static void main(String[] argv) {
|
||||
FileReader in;
|
||||
FileWriter out;
|
||||
try {
|
||||
in = new FileReader("infos.txt");
|
||||
out = new FileWriter("rendu_infos.txt");
|
||||
int c;
|
||||
while((c=in.read()) != 1) {
|
||||
out.write(c);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
26
initiationJava/src/partie6/TestPoint.java
Normal file
26
initiationJava/src/partie6/TestPoint.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package partie6;
|
||||
|
||||
public class TestPoint {
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
Point a = new Point(1,4);
|
||||
a.affiche();
|
||||
a.deplace(-2, 3);
|
||||
a.affiche();
|
||||
}
|
||||
catch (ErrConst e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("Abs : " + e.getAbs());
|
||||
System.out.println("Ord : " + e.getOrd());
|
||||
System.exit(-1);
|
||||
}
|
||||
catch(ErrDepl e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("Déplacement Abs : " + e.getDlAbs());
|
||||
System.out.println("Déplacement Ord : " + e.getDlOrd());
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue