diff --git a/src/tp01/Book.class b/src/tp01/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..fae094ede72fbedad68de4fdf6f2854ab1fffce2 Binary files /dev/null and b/src/tp01/Book.class differ diff --git a/src/tp01/Book.java b/src/tp01/Book.java new file mode 100644 index 0000000000000000000000000000000000000000..ffcd5c3e4d783944568b8e1a865ae60e405e8a0c --- /dev/null +++ b/src/tp01/Book.java @@ -0,0 +1,29 @@ +class Book +{ + // class attributes + String author; + String title; + int year; + // constructor + Book(String author, String title, int year) { + this.author = author; + this.title = title; + this.year = year; + } + // methods + String getAuthor() { + return this.author; + } + String getTitle() { + return this.title; + } + String print() { + return author + "\t" + title + "\t" + year; + } + + @Override + public String toString() + { + return author + " a écrit " + title + " en " + year; + } +} \ No newline at end of file diff --git a/src/tp01/HighScore.class b/src/tp01/HighScore.class new file mode 100644 index 0000000000000000000000000000000000000000..1314cac92585ed95bf22ef227e32965f1fb5136c Binary files /dev/null and b/src/tp01/HighScore.class differ diff --git a/src/tp01/HighScore.java b/src/tp01/HighScore.java new file mode 100644 index 0000000000000000000000000000000000000000..84a91d36fe941b7d762978877ab68687905c7ae8 --- /dev/null +++ b/src/tp01/HighScore.java @@ -0,0 +1,47 @@ +public class HighScore +{ + Score[] top; + + public HighScore(int numberPod) + { + this.top = new Score[numberPod]; + } + + @Override + public String toString() + { + return "1. " + top[0] + "\n2. " + top[1] + "\n3. " + top[2]; + } + + boolean ajout(Score newScore) + { + for(int i = 0;i < top.length;i++) + { + if(top[i] != null) + { + if(newScore.sc > top[i].sc) + { + top[i+2] = top[i+1]; + top[i+1] = top[i]; + top[i] = newScore; + } + else if(newScore.sc > top[i+1].sc) + { + top[i+2] = top[i+1]; + top[i+1] = newScore; + } + else if(newScore.sc > top[i+2].sc) + { + top[i+2] = newScore; + } + return true; + } + else + { + top[i] = newScore; + return true; + } + } + return false; + } +} diff --git a/src/tp01/Parameter.class b/src/tp01/Parameter.class new file mode 100644 index 0000000000000000000000000000000000000000..4307d6e1f3071de184d766828bcb55e4dce86d8c Binary files /dev/null and b/src/tp01/Parameter.class differ diff --git a/src/tp01/Parameter.java b/src/tp01/Parameter.java new file mode 100644 index 0000000000000000000000000000000000000000..20e81b67b19cfbc35de5cdc03be1b44671d5b2a2 --- /dev/null +++ b/src/tp01/Parameter.java @@ -0,0 +1,12 @@ +public class Parameter +{ + public static void main(String[] args) + { + if(args.length==0) { + System.out.println("No parameter"); + } + for(int i=0; i<args.length; i++) { + System.out.println("(" + (i+1) + ") " + args[i]); + } + } +} diff --git a/src/tp01/RandomSequence.class b/src/tp01/RandomSequence.class new file mode 100644 index 0000000000000000000000000000000000000000..e320489c0fa17b9d2182c303ac32b59cb36e20d4 Binary files /dev/null and b/src/tp01/RandomSequence.class differ diff --git a/src/tp01/RandomSequence.java b/src/tp01/RandomSequence.java new file mode 100644 index 0000000000000000000000000000000000000000..c6cd0eea76c08452a8fe0965c176284d8aed367b --- /dev/null +++ b/src/tp01/RandomSequence.java @@ -0,0 +1,46 @@ +import java.util.Random; + +public class RandomSequence +{ + int nbGen; + int valMax; + String intOrReal = "INTEGER"; + + public RandomSequence(int n, int v, String i) + { + this.nbGen = n; + this.valMax = v; + this.intOrReal = i; + } + public static void main(String[] args) + { + if(Integer.parseInt(args[0]) >= 1 && Integer.parseInt(args[1]) >= 1) + { + Random rnd = new Random(); + if(args[2].equals("REAL")) + { + String rep = ""; + for(int i = 1;i<=Integer.parseInt(args[0]);i++) + { + double db = rnd.nextDouble(Double.parseDouble(args[1])); + rep = rep + "Valeur n°"+i+" : "+db + "\n"; + } + System.out.println(rep); + } + else + { + String rep = ""; + for(int i = 1;i<=Integer.parseInt(args[0]);i++) + { + int in = rnd.nextInt(Integer.parseInt(args[1])); + rep = rep + "Valeur n°"+i+" : "+in + "\n"; + } + System.out.println(rep); + } + } + else + { + System.out.println("Correct usage : <nbElt> <maxVal> [INTEGER|REAL]"); + } + } +} \ No newline at end of file diff --git a/src/tp01/Score.class b/src/tp01/Score.class new file mode 100644 index 0000000000000000000000000000000000000000..2fad8df9879ae023b1c8af80665824eaa5117aec Binary files /dev/null and b/src/tp01/Score.class differ diff --git a/src/tp01/Score.java b/src/tp01/Score.java new file mode 100644 index 0000000000000000000000000000000000000000..88e4f821e50fe632ca2dc8b84cf09caadeac5240 --- /dev/null +++ b/src/tp01/Score.java @@ -0,0 +1,19 @@ +public class Score +{ + String n = "Empty"; + int sc = 0; + String tS = "00/00"; + + public Score(String name, int score, String timestamp) + { + this.n = name; + this.sc = score; + this.tS = timestamp; + } + + @Override + public String toString() + { + return tS + " " + n + " = " + sc + "."; + } +} \ No newline at end of file diff --git a/src/tp01/UseBook.class b/src/tp01/UseBook.class new file mode 100644 index 0000000000000000000000000000000000000000..2abb5d2f3acc39418b9c3c3614d1c99770dccd20 Binary files /dev/null and b/src/tp01/UseBook.class differ diff --git a/src/tp01/UseBook.java b/src/tp01/UseBook.java new file mode 100644 index 0000000000000000000000000000000000000000..ed177ab11d9e9d8543832b434ab392041ec266e6 --- /dev/null +++ b/src/tp01/UseBook.java @@ -0,0 +1,15 @@ +/* Classe Init Principale */ +public class UseBook +{ + public static void main(String[] args) + { + Book[] biblio = new Book[3]; + biblio[0] = new Book("Edwin A. Abbott", "Flatland", 1884); + biblio[1] = new Book("Picasso", "L'art de la peinture", 1886); + biblio[2] = new Book("Samuel Monet", "Les attrocités de la guerre", 1985); + for(int i = 0;i<3; i++) + { + System.out.println(biblio[i]); + } + } +} \ No newline at end of file diff --git a/src/tp01/UseHighScore.class b/src/tp01/UseHighScore.class new file mode 100644 index 0000000000000000000000000000000000000000..7151308fc620c9687232838fb0cf6702bf8698f2 Binary files /dev/null and b/src/tp01/UseHighScore.class differ diff --git a/src/tp01/UseHighScore.java b/src/tp01/UseHighScore.java new file mode 100644 index 0000000000000000000000000000000000000000..16c382bb5a05453d7890f735c12334c3127331b1 --- /dev/null +++ b/src/tp01/UseHighScore.java @@ -0,0 +1,12 @@ +public class UseHighScore +{ + public static void main(String[] args) + { + HighScore hSc = new HighScore(3); + hSc.ajout(new Score("Alice", 300, "29/01")); + hSc.ajout(new Score("Bob", 800, "29/01")); + hSc.ajout(new Score("Alice", 42, "30/01")); + hSc.ajout(new Score("Alice", 650, "31/01")); + System.out.println(hSc); + } +} diff --git a/src/tp02/Competitor.class b/src/tp02/Competitor.class new file mode 100644 index 0000000000000000000000000000000000000000..0ef5ef542e7c366764cf6b79e3da4e817d399f87 Binary files /dev/null and b/src/tp02/Competitor.class differ diff --git a/src/tp02/Competitor.java b/src/tp02/Competitor.java new file mode 100644 index 0000000000000000000000000000000000000000..b934245c32ef60e44ed21da8f389de38a3bdeb85 --- /dev/null +++ b/src/tp02/Competitor.java @@ -0,0 +1,52 @@ +public class Competitor +{ + private int t, s; + private String numberSign; + + public Competitor(int numberSign, int score, int min, int sec) + { + if(numberSign>=1 && numberSign<=100) + { + this.numberSign = "No"+numberSign; + } + if(score>=0 && score<=50) + { + this.s = score; + } + if(sec>=0 && sec<=60 && min>=0 && min<=60) + { + this.t = (60*min) + sec; + } + } + + String display() + { + if(numberSign == null) + { + return "[<invalide>,"+s+" points,"+t+" s]"; + } + return "["+numberSign+","+s+" points,"+t+" s]"; + } + + public boolean equals(Competitor c) + { + if(this == c) { return true; } + if(c == null) { return false; } + if(c.numberSign.equals(this.numberSign) && c.s == this.s) + { return true; } + return false; + } + + boolean isFaster(Competitor other) + { + if(this == other) + {return false;} + if(other == null) + {return false;} + if(other.t < this.t) + { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/tp02/Dice.class b/src/tp02/Dice.class new file mode 100644 index 0000000000000000000000000000000000000000..ff61924c06acfb80c1770b6030c6fe1ece8a73a6 Binary files /dev/null and b/src/tp02/Dice.class differ diff --git a/src/tp02/Dice.java b/src/tp02/Dice.java new file mode 100644 index 0000000000000000000000000000000000000000..83c412e22e6d0031fd4084ae0645ba9ccc988a5b --- /dev/null +++ b/src/tp02/Dice.java @@ -0,0 +1,36 @@ +import java.util.Random; + +public class Dice +{ + private Random rand = new Random(); + private int numberSides; + private int value; + + public Dice(int n) + { + if(n > 1) + { + this.numberSides = n; + } + else + { + this.numberSides = 1; + } + } + + public void roll() + { + value = rand.nextInt(numberSides)+1; + } + + public int getValue() + { + return value; + } + + @Override + public String toString() + { + return "Valeur du dee = " + getValue(); + } +} \ No newline at end of file diff --git a/src/tp02/DicePlayer.class b/src/tp02/DicePlayer.class new file mode 100644 index 0000000000000000000000000000000000000000..e3df4ceec9815a72b0dc1819bf95b603795487fe Binary files /dev/null and b/src/tp02/DicePlayer.class differ diff --git a/src/tp02/DicePlayer.java b/src/tp02/DicePlayer.java new file mode 100644 index 0000000000000000000000000000000000000000..8728c757505940c04cc0d5f559465cf2542fddcf --- /dev/null +++ b/src/tp02/DicePlayer.java @@ -0,0 +1,53 @@ +public class DicePlayer +{ + private String nm; + private int totalValue; + private int nbDiceRolls; + + public DicePlayer(String name) + { + this.nm = name; + } + + public void play(Dice dice6) + { + nbDiceRolls = 0; + while (this.totalValue < 20) + { + nbDiceRolls=nbDiceRolls+1; + dice6.roll(); + System.out.println(this.nm + ": "+nbDiceRolls+" lancer: "+dice6); + this.totalValue = this.totalValue+dice6.getValue(); + } + } + + public void setNbDiceRolls(int a) + { + this.nbDiceRolls=a; + } + + public int getNbDiceRolls() + { + return nbDiceRolls; + } + + public String getName() + { + return nm; + } + + public boolean isWinning(DicePlayer p) + { + if(p.nbDiceRolls < this.nbDiceRolls) + { + return true; + } + return false; + } + + @Override + public String toString() + { + return this.nm+": "+this.totalValue+" points en "+this.nbDiceRolls+" coups."; + } +} \ No newline at end of file diff --git a/src/tp02/NDicePlayerGame.class b/src/tp02/NDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..19bffc194503f94fb969620be8d032033284fd23 Binary files /dev/null and b/src/tp02/NDicePlayerGame.class differ diff --git a/src/tp02/NDicePlayerGame.java b/src/tp02/NDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..eadc7266a6a4177b7ac7cd6d83770986cf96df42 --- /dev/null +++ b/src/tp02/NDicePlayerGame.java @@ -0,0 +1,72 @@ +public class NDicePlayerGame +{ + private int acreate; + private DicePlayer[] players; + + public NDicePlayerGame(int creerJoueur) + { + this.acreate = creerJoueur; + players = new DicePlayer[creerJoueur]; + } + + public int getJoueurCreer() + { + return acreate; + } + + public DicePlayer[] creer(int a, DicePlayer p) + { + players[a] = p; + return players; + } + + public DicePlayer[] winner() + { + DicePlayer n = new DicePlayer("Pro"); + n.setNbDiceRolls(99); + DicePlayer[] vainqueur = {}; + int min = 99; + for (int i = 0; i < players.length-1; i++) + { + if(players[i].getNbDiceRolls() < min) + { + min = players[i].getNbDiceRolls(); + } + } + for (int i = 0; i < min-1; i++) + { + for (int k = 0; k < players.length-1; k++) + { + if(players[k].getNbDiceRolls() == min) + { + vainqueur[i] = players[k]; + } + } + } + return vainqueur; + } + + public static void main(String[] args) + { + Dice dee = new Dice(6); + DicePlayer player1 = new DicePlayer("Alice"); + DicePlayer player2 = new DicePlayer("Gordon"); + DicePlayer player3 = new DicePlayer("Nils"); + DicePlayer player4 = new DicePlayer("Samuel"); + + NDicePlayerGame jeux = new NDicePlayerGame(4); + jeux.creer(0, player1); + jeux.creer(1, player2); + jeux.creer(2, player3); + jeux.creer(3, player4); + player1.play(dee); + player2.play(dee); + player3.play(dee); + player4.play(dee); + DicePlayer[] tb = jeux.winner(); + for (int index = 0; index < jeux.winner().length; index++) + { + System.out.println("Vainqueur "+index+": " + tb[index]); + } + } +} \ No newline at end of file diff --git a/src/tp02/OneDicePlayerGame.class b/src/tp02/OneDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..e12ad15add7620ebbbf9b942a1c3191e6f3b6c7e Binary files /dev/null and b/src/tp02/OneDicePlayerGame.class differ diff --git a/src/tp02/OneDicePlayerGame.java b/src/tp02/OneDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..1ef9b90567f88d12fd52d13183794831fbef9868 --- /dev/null +++ b/src/tp02/OneDicePlayerGame.java @@ -0,0 +1,10 @@ +public class OneDicePlayerGame +{ + public static void main(String[] args) + { + Dice dee = new Dice(6); + DicePlayer player = new DicePlayer("Alice"); + player.play(dee); + System.out.println(player); + } +} \ No newline at end of file diff --git a/src/tp02/TwoDicePlayerGame.class b/src/tp02/TwoDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..714b476d1adfac42ed449950af623fb1c577902d Binary files /dev/null and b/src/tp02/TwoDicePlayerGame.class differ diff --git a/src/tp02/TwoDicePlayerGame.java b/src/tp02/TwoDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..6ea8d02f61cee29d3de722edd107dcf7fbb0bb35 --- /dev/null +++ b/src/tp02/TwoDicePlayerGame.java @@ -0,0 +1,29 @@ +public class TwoDicePlayerGame +{ + DicePlayer p1, p2; + + public TwoDicePlayerGame(DicePlayer p1, DicePlayer p2) + { + this.p1 = p1; + this.p2 = p2; + } + + public DicePlayer winner() + { + if(p1.isWinning(p2)) + { + return p2; + } + return p1; + } + public static void main(String[] args) + { + Dice dee = new Dice(6); + DicePlayer player1 = new DicePlayer("Alice"); + DicePlayer player2 = new DicePlayer("Gordon"); + TwoDicePlayerGame jeux = new TwoDicePlayerGame(player1, player2); + player1.play(dee); + player2.play(dee); + System.out.println("Vainqueur: " + jeux.winner()); + } +} \ No newline at end of file diff --git a/src/tp02/UseCompetitor.class b/src/tp02/UseCompetitor.class new file mode 100644 index 0000000000000000000000000000000000000000..3e0f0eca8cd05cc6273057c9291d3ce6b0b31484 Binary files /dev/null and b/src/tp02/UseCompetitor.class differ diff --git a/src/tp02/UseCompetitor.java b/src/tp02/UseCompetitor.java new file mode 100644 index 0000000000000000000000000000000000000000..fbd091d2bf3478fe33702c1040be784fc584f585 --- /dev/null +++ b/src/tp02/UseCompetitor.java @@ -0,0 +1,30 @@ +public class UseCompetitor { + public static void main(String[] args) + { + /*Competitor alice = new Competitor(1, 45, 15, 20); + Competitor bruno = new Competitor(1, 45, 15, 20); + Competitor clement = new Competitor(2, 32, 12, 45); + Competitor dora = new Competitor(2, 34, 12, 45); + System.out.println("Alice:" + alice.display() + " Bruno:" + bruno.display() + "->" + alice.equals(bruno)); + System.out.println("Alice:" + alice + " null:" + null + "->" + alice.equals(null)); + System.out.println("Alice:" + alice + " Alice:" + alice + "->" + alice.equals(alice)); + System.out.println("Alice:" + alice + " Clement:" + clement + "->" + alice.equals(clement)); + System.out.println("Clement:" + clement + " Dora:" + dora + "->" + clement.equals(dora)); + System.out.println(alice.isFaster(dora));*/ + + Competitor[] compet = new Competitor[100]; + compet[0] = new Competitor(1,45,15,20); + compet[1] = new Competitor(2,32,12,45); + compet[4] = new Competitor(5,12,13,59); + compet[11] = new Competitor(12,12,15,70); + compet[31] = new Competitor(32,75,15,20); + + for (int index = 0; index < compet.length; index++) + { + if(!(compet[index] == null)) + { + System.out.println(compet[index].display()); + } + } + } +} diff --git a/src/tp03/Card.java b/src/tp03/Card.java new file mode 100644 index 0000000000000000000000000000000000000000..1907b430232f15e82a759c26418e757c824e1e2d --- /dev/null +++ b/src/tp03/Card.java @@ -0,0 +1,63 @@ +public class Card +{ + private Color c; + private Rank r; + + public Card(Color color, Rank rank) + { + this.c = color; + this.r = rank; + } + + public Card(String color, String rank) + { + + } + + public Color getColor() + { + return this.c; + } + + public Rank getRank() + { + return this.r; + } + + public int compareRank(Card c) + { + if(this == c) { return 0; } + if(c.r==this.r) { return 0; } + if(this.r.ordinal() < c.r.ordinal()) { return -1; } + if(this.r.ordinal() > c.r.ordinal()) { return 1; } + return 2; + } + + public int compareColor(Card c) + { + if(this == c) { return 0; } + if(c.c==this.c) { return 0; } + if(this.c.ordinal() < c.c.ordinal()) { return -1; } + if(this.c.ordinal() > c.c.ordinal()) { return 1; } + return 2; + } + + public boolean isBefore(Card c) + { + return true; + } + + public boolean equals(Card c) + { + if(this == c) { return true; } + if(c == null) { return false; } + if(c.c==this.c && c.r == this.r) + { return true; } + return false; + } + + @Override + public String toString() { + return "mc"; + } +} \ No newline at end of file diff --git a/src/tp03/Color.java b/src/tp03/Color.java new file mode 100644 index 0000000000000000000000000000000000000000..ecf2a5fa780b28ffe43d08fe4d5ac75b0da30647 --- /dev/null +++ b/src/tp03/Color.java @@ -0,0 +1,4 @@ +public enum Color +{ + CLUB, DIAMOND, HEART, SPADE; +} \ No newline at end of file diff --git a/src/tp03/Rank.java b/src/tp03/Rank.java new file mode 100644 index 0000000000000000000000000000000000000000..713b16ed4e9fbc5ccdf806956ad368be1a6a880a --- /dev/null +++ b/src/tp03/Rank.java @@ -0,0 +1,4 @@ +public enum Rank +{ + SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE; +} diff --git a/src/tp03/UseCard.java b/src/tp03/UseCard.java new file mode 100755 index 0000000000000000000000000000000000000000..fe7f8a2c418d643c5eeeb2b38cd96e48a40f9ce1 --- /dev/null +++ b/src/tp03/UseCard.java @@ -0,0 +1,21 @@ +public class UseCard { + public static void main(String[] args) { + Card c1 = new Card(Color.HEART, Rank.TEN); + Card c2 = new Card(Color.HEART, Rank.JACK); + Card c3 = new Card(Color.DIAMOND, Rank.TEN); + Card c4 = new Card(Color.CLUB, Rank.SEVEN); + Card c5 = new Card(Color.SPADE, null); + Card c6 = new Card(null, Rank.JACK); + Card c7 = new Card(Color.HEART, Rank.TEN); + // equals scenario + if(!c1.equals(c1) || c1.equals(null) || c1.equals(c2) || c1.equals(c3) || c1.equals(c4) || c1.equals(c5) || c1.equals(c6) || !c1.equals(c7)) + System.out.println("equals FAILED"); + // compareColor scenario + else if(c1.compareColor(c1) != 0 || c1.compareColor(c2) != 0 || c1.compareColor(c3) <= 0 || c1.compareColor(c4) <= 0 || c1.compareColor(c5) >= 0 || c1.compareColor(c7) != 0) + System.out.println("compareColor FAILED"); + // compareRank scenario + else if(c1.compareRank(c1) != 0 || c1.compareRank(c2) >= 0 || c1.compareRank(c3) != 0 || c1.compareRank(c4) <= 0 || c1.compareRank(c6) >= 0 || c1.compareRank(c7) != 0) + System.out.println("compareRank FAILED"); + else System.out.println("Tests OK"); + } +}