first commit
This commit is contained in:
BIN
TP_DEV3.2/Genericite/Exo1.class
Normal file
BIN
TP_DEV3.2/Genericite/Exo1.class
Normal file
Binary file not shown.
69
TP_DEV3.2/Genericite/Exo1.java
Normal file
69
TP_DEV3.2/Genericite/Exo1.java
Normal file
@@ -0,0 +1,69 @@
|
||||
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||
|
||||
|
||||
|
||||
public class Exo1 {
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
List<Integer> liste1 = new ArrayList<>();
|
||||
liste1.add(9);
|
||||
liste1.add(1);
|
||||
|
||||
|
||||
|
||||
List<Number> liste2 = new ArrayList<>();
|
||||
liste2.add(15);
|
||||
liste2.add(1.5f);
|
||||
liste2.add(15000L);
|
||||
|
||||
|
||||
List<Float> liste3 = new ArrayList<>();
|
||||
liste3.add(3.93f);
|
||||
liste3.add(3.07f);
|
||||
|
||||
System.out.println("liste 1 (Integer) ="+ liste1);
|
||||
System.out.println("liste 2 (Number) ="+ liste2);
|
||||
System.out.println("liste 3 (Float) ="+ liste3);
|
||||
|
||||
|
||||
liste2.addAll(liste1);
|
||||
liste2.addAll(liste3);
|
||||
|
||||
System.out.println("Apres versement des liste 1 et 3 dans la 2" + liste2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
TP_DEV3.2/Genericite/Exodeux.class
Normal file
BIN
TP_DEV3.2/Genericite/Exodeux.class
Normal file
Binary file not shown.
83
TP_DEV3.2/Genericite/Exodeux.java
Normal file
83
TP_DEV3.2/Genericite/Exodeux.java
Normal file
@@ -0,0 +1,83 @@
|
||||
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||
|
||||
public class Exodeux {
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
|
||||
|
||||
AfficherTouslesArgs(args);
|
||||
AfficherLes5erArgs(args);
|
||||
trierEtAfficherNaturel(args);
|
||||
trierEtAffiicherSansCasse(args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void AfficherTouslesArgs(String[] arguments){
|
||||
|
||||
|
||||
String TousLesArgsTransforme = Arrays.toString(arguments);
|
||||
System.out.println("Voici tous les args " + TousLesArgsTransforme);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void AfficherLes5erArgs(String[] arguments) {
|
||||
|
||||
int limite = Math.min(5, arguments.length);
|
||||
String[] premier = Arrays.copyOf(arguments,limite);
|
||||
System.out.println("Voici les 5er arguments : "+Arrays.toString(premier));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void trierEtAfficherNaturel(String[] args) {
|
||||
|
||||
|
||||
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||
|
||||
Arrays.sort(copyArgument);
|
||||
|
||||
String NaturelTriage = Arrays.toString(copyArgument);
|
||||
|
||||
System.out.println("Tri naturel" + NaturelTriage);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void trierEtAffiicherSansCasse(String[] args){
|
||||
|
||||
|
||||
|
||||
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||
Arrays.sort(copyArgument,String::compareToIgnoreCase);
|
||||
String SansCasseTrierNickelChrome = Arrays.toString(copyArgument);
|
||||
System.out.println("Tri sans casse naturel : "+ SansCasseTrierNickelChrome);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
@@ -0,0 +1,106 @@
|
||||
public class Exotrois {
|
||||
|
||||
|
||||
public static <T> plusFrequent(T[] tableau){
|
||||
|
||||
|
||||
T valeurGagnante = tableau[0];
|
||||
int frequenceGagnante = 0;
|
||||
int premierIndexGagnant = tableau.length;
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<tableau.length; i++){
|
||||
|
||||
|
||||
|
||||
T valeurCourante = tableau[i];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int frequenceCourante =0;
|
||||
for(int k=0; k<tableau.length; k++){
|
||||
|
||||
if(Object.equals(tableau[k], valeurCourante)){
|
||||
|
||||
frequenceCourante++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
int premierIndexCourant = -1;
|
||||
for(int j=0; j<tableau.length; j++){
|
||||
|
||||
if(Object.equals(tableau[j]), valeurCourante){
|
||||
|
||||
premierIndexCourant=j;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
TP_DEV3.2/Liste/Luminance.class
Normal file
BIN
TP_DEV3.2/Liste/Luminance.class
Normal file
Binary file not shown.
107
TP_DEV3.2/Liste/Luminance.java
Normal file
107
TP_DEV3.2/Liste/Luminance.java
Normal file
@@ -0,0 +1,107 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class Luminance extends JPanel implements MouseListener {
|
||||
|
||||
private final Random random = new Random();
|
||||
private final List<Color> couleurs = new LinkedList<>();
|
||||
|
||||
private static final int NB_COULEURS = 10;
|
||||
private static final int LARGEUR = 60;
|
||||
private static final int HAUTEUR = 80;
|
||||
private static final int ESPACE = 8;
|
||||
private static final int INCLINAISON = 15; // décalage pour le parallélogramme
|
||||
|
||||
public Luminance() {
|
||||
for (int i = 0; i < NB_COULEURS; i++) {
|
||||
int r = random.nextInt(256);
|
||||
int g = random.nextInt(256);
|
||||
int b = random.nextInt(256);
|
||||
couleurs.add(new Color(r, g, b));
|
||||
}
|
||||
|
||||
int largeurFenetre = (LARGEUR + ESPACE) * NB_COULEURS + 40;
|
||||
int hauteurFenetre = HAUTEUR + 60;
|
||||
this.setPreferredSize(new Dimension(largeurFenetre, hauteurFenetre));
|
||||
addMouseListener(this);
|
||||
}
|
||||
|
||||
public int LuminenceApp(Color c) {
|
||||
int rouge = c.getRed();
|
||||
int vert = c.getGreen();
|
||||
int bleu = c.getBlue();
|
||||
return (21 * rouge + 72 * vert + 7 * bleu) / 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
super.paintComponent(pinceau);
|
||||
Graphics g = pinceau;
|
||||
|
||||
int x = 20;
|
||||
int y = 20;
|
||||
|
||||
for (Color c : couleurs) {
|
||||
g.setColor(c);
|
||||
|
||||
// dessin d’un parallélogramme
|
||||
int[] xs = {x + INCLINAISON, x + LARGEUR + INCLINAISON, x + LARGEUR, x};
|
||||
int[] ys = {y, y, y + HAUTEUR, y + HAUTEUR};
|
||||
Polygon p = new Polygon(xs, ys, 4);
|
||||
|
||||
g.fillPolygon(p);
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
g.drawPolygon(p);
|
||||
|
||||
x = x + LARGEUR + ESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
private int indexAt(int mx, int my) {
|
||||
int x = 20;
|
||||
int y = 20;
|
||||
|
||||
for (int i = 0; i < couleurs.size(); i++) {
|
||||
int[] xs = {x + INCLINAISON, x + LARGEUR + INCLINAISON, x + LARGEUR, x};
|
||||
int[] ys = {y, y, y + HAUTEUR, y + HAUTEUR};
|
||||
Polygon p = new Polygon(xs, ys, 4);
|
||||
|
||||
if (p.contains(mx, my)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
x = x + LARGEUR + ESPACE;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int intervalle = indexAt(e.getX(), e.getY());
|
||||
if (intervalle >= 0) {
|
||||
Color c = couleurs.get(intervalle);
|
||||
System.out.println("Luminance = " + LuminenceApp(c) +
|
||||
" (R = " + c.getRed() + " G = " + c.getGreen() + " B = " + c.getBlue() + ")");
|
||||
couleurs.remove(intervalle);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void mousePressed(MouseEvent e) {}
|
||||
@Override public void mouseReleased(MouseEvent e) {}
|
||||
@Override public void mouseEntered(MouseEvent e) {}
|
||||
@Override public void mouseExited(MouseEvent e) {}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame f = new JFrame("Luminence");
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setContentPane(new Luminance());
|
||||
f.pack();
|
||||
f.setLocationRelativeTo(null);
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
33
TP_DEV3.2/Liste/Maillon.java
Normal file
33
TP_DEV3.2/Liste/Maillon.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
public class ChainedList<E> implements List<E>{
|
||||
|
||||
|
||||
|
||||
|
||||
public static class Node<E>{
|
||||
|
||||
|
||||
|
||||
E value;
|
||||
Node<E> next;
|
||||
Node(E v){
|
||||
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
51
TP_DEV3.2/Piles/Arithmetique.java
Normal file
51
TP_DEV3.2/Piles/Arithmetique.java
Normal file
@@ -0,0 +1,51 @@
|
||||
import java.util.Stack;
|
||||
|
||||
public class Arithmetique {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Exemple : 18 6 1 2 + 9 + / + 8 7 - *
|
||||
// String[] args = {"18", "6", "1", "2", "+", "9", "+", "/", "+", "8", "7", "-", "*"};
|
||||
|
||||
Stack<Integer> pile = new Stack<>();
|
||||
|
||||
for (String element : args) {
|
||||
if (estNombre(element)) {
|
||||
// Si c’est un nombre, on le met dans la pile
|
||||
pile.push(Integer.parseInt(element));
|
||||
} else {
|
||||
// Sinon c’est un opérateur on dépile 2 valeurs
|
||||
int b = pile.pop();
|
||||
int a = pile.pop();
|
||||
int resultat = calculer(a, b, element);
|
||||
// On empile le résultat
|
||||
pile.push(resultat);
|
||||
}
|
||||
}
|
||||
|
||||
// À la fin, il reste le résultat final dans la pile
|
||||
System.out.println("Résultat = " + pile.pop());
|
||||
}
|
||||
|
||||
// Vérifie si une chaîne est un nombre
|
||||
public static boolean estNombre(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Calcule a (op) b
|
||||
public static int calculer(int a, int b, String op) {
|
||||
switch (op) {
|
||||
case "+": return a + b;
|
||||
case "-": return a - b;
|
||||
case "*": return a * b;
|
||||
case "/": return a / b;
|
||||
default:
|
||||
throw new IllegalArgumentException("Opérateur inconnu : " + op);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
TP_DEV3.2/Piles/Pile.java
Normal file
20
TP_DEV3.2/Piles/Pile.java
Normal file
@@ -0,0 +1,20 @@
|
||||
public class Pile {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
TP_DEV3.2/Recursivité/Appels.class
Normal file
BIN
TP_DEV3.2/Recursivité/Appels.class
Normal file
Binary file not shown.
48
TP_DEV3.2/Recursivité/Appels.java
Normal file
48
TP_DEV3.2/Recursivité/Appels.java
Normal file
@@ -0,0 +1,48 @@
|
||||
import java.io.*;
|
||||
import java.lang.Thread;
|
||||
|
||||
public class Appels {
|
||||
|
||||
|
||||
public static int Factorielle (int n){
|
||||
|
||||
Thread.dumpStack();
|
||||
|
||||
if(n==0){
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return n*Factorielle(n-1);
|
||||
|
||||
}
|
||||
|
||||
/*System.out.println()
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
|
||||
if(args.length != 1){
|
||||
|
||||
System.out.println("Usage : java Appel <entier>");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int n = Integer.parseInt(args[0]);
|
||||
|
||||
int resultat = Factorielle(n);
|
||||
|
||||
System.out.println(n+"! = " + resultat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
19
TP_DEV3.2/Recursivité/Fibonacci.java
Normal file
19
TP_DEV3.2/Recursivité/Fibonacci.java
Normal file
@@ -0,0 +1,19 @@
|
||||
public class Fibonacci {
|
||||
|
||||
|
||||
|
||||
|
||||
public int Fibonacci (int a){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
TP_DEV3.2/Recursivité/Tableaux.class
Normal file
BIN
TP_DEV3.2/Recursivité/Tableaux.class
Normal file
Binary file not shown.
82
TP_DEV3.2/Recursivité/Tableaux.java
Normal file
82
TP_DEV3.2/Recursivité/Tableaux.java
Normal file
@@ -0,0 +1,82 @@
|
||||
public class Tableaux{
|
||||
|
||||
public static void remplir(String[] args, int[] tab, int i) {
|
||||
// Cas de base
|
||||
if (i == args.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cas récursif
|
||||
tab[i] = Integer.parseInt(args[i]);
|
||||
remplir(args, tab, i + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void AfficheTableaux(int[] tab, int i){
|
||||
|
||||
if(i==tab.length){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
System.out.println(tab[i]);
|
||||
AfficheTableaux(tab,i+1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void AfficheTableauxInverse(int[] tab, int i){
|
||||
if(i<0){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
System.out.println(tab[i]);
|
||||
AfficheTableauxInverse(tab, i-1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static int MaxTab(int[] tab, int i){
|
||||
|
||||
if(i==tab.length-1){
|
||||
|
||||
|
||||
return tab[i];
|
||||
|
||||
|
||||
}
|
||||
|
||||
int maxRestant=MaxTab(tab,i+1);
|
||||
return Math.max(tab[i], maxRestant);
|
||||
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
|
||||
|
||||
if(args.length <1){
|
||||
|
||||
System.out.println("Usage : java Tableaux <entier>");
|
||||
return;
|
||||
|
||||
}
|
||||
int[] tab = new int[args.length];
|
||||
remplir(args,tab,0);
|
||||
AfficheTableaux(tab, 0);
|
||||
AfficheTableauxInverse(tab,tab.length-1);
|
||||
int max = MaxTab(tab,0);
|
||||
System.out.println("Le maximum est :"+ max);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user