Skip to content
Snippets Groups Projects
Commit a6cd29f8 authored by Maxence Antoine's avatar Maxence Antoine
Browse files

commit initial

parent 354da17a
No related branches found
No related tags found
No related merge requests found
Showing with 380 additions and 1 deletion
*.class
**/bin
\ No newline at end of file
bin/
.vscode/
File added
File added
File added
//Auteur: Maxence Antoine
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 + " a écrit " + title + " en " + year;
}
public static void main(String[] args){
Book livre = new Book("Edwin A. Abbott", "Flatland", 1884);
System.out.println(livre.print());
}
}
public class HighScore {
Score[] top;
HighScore(int top) {
this.top = top;
}
boolean ajout(Score newScore){
}
int seqSearch(Score[] scores ,int target, int begin, int end) {
for(int i = begin; i<end; ++i) {
if (target == scores[i].score) {
return i;
}
}
return -1;
}
int binarySearch(Score[] scores, int target, int deb, int fin) {
while(deb <= fin) {
int mid = deb + (fin-deb)/2;
if(scores[mid].score < target) {
deb = mid +1;
}
else if (scores[mid].score > target) {
fin = mid -1;
}
else if (scores[mid].score == target) {
}
}
}
}
//Auteur: Maxence Antoine
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]);
}
}
}
//Auteur: Maxence Antoine
public class RandomSequence {
public static void main(String[] args) {
if (args.length <2 || args.length > 3 || args[0].contains(".")) {
System.err.println("Correct usage : <nbElt> <maxVal> [INTEGER|REAL]");
}else {
int nbElt;
int maxVal;
double maxValD;
if (args.length == 3 && args[2].equals("REAL")){
nbElt = Integer.parseInt(args[0]);
maxValD = Double.parseDouble(args[1]);
for (int i = 0; i<nbElt; ++i) {
System.out.println((Math.random()*maxValD)+1);
}
}
else {
nbElt = Integer.parseInt(args[0]);
maxVal = Integer.parseInt(args[1]);
for (int i = 0; i<nbElt; ++i) {
System.out.println((int)(Math.random()*maxVal)+1);
}
}
}
}
}
//Auteur: Maxence Antoine
public class Score {
String name;
int score;
String timestamp;
Score(String name, int score, String timestamp){
this.name = name;
this.score = score;
this.timestamp = timestamp;
}
String toString(String name, int score, String timestamp) {
return "("+timestamp+") "+ name + " = "+ score;
}
}
//Auteur : Maxence Antoine
class UseBook {
public static void main(String[] args){
Book livre1 = new Book("Stephen King", "It", 1986);
Book livre2 = new Book("George Orwell", "1984", 1949);
Book livre3 = new Book("Jules Verne", "Voyage au centre de la Terre", 1864);
Book biblio[] = new Book[] {livre1, livre2, livre3};
for(int i = 0; i < biblio.length ; ++i ) {
System.out.println(biblio[i].print());
}
}
}
\ No newline at end of file
// Auteur : Maxence Antoine
public class Competitor {
private String numberSign;
private int time;
private int score;
// Constructeur
Competitor(int numberSign, int score, int min, int sec){
if(numberSign >= 1 && numberSign <= 100 && min >= 0 && min <= 60 && sec >= 0 && sec <= 60 && score >= 0 && score <= 50){
this.numberSign = "No" + numberSign;
this.time = min*60 + sec;
this.score = score;
}else {
this.numberSign = null;
}
}
// Méthodes
String display(){
if(this.numberSign == null) {
return "[<invalide>, " + this.score + " points, " + this.time + " s]";
}else {
return "[" + this.numberSign + "," + this.score + " points, " + this.time + " s]";
}
}
boolean equals(Competitor other){
if (other != null) {
if(this.numberSign.equals(other.numberSign) && this.score == other.score) {
return true;
}
}
return false;
}
boolean isFaster(Competitor other) {
if(other == null) {
return true;
}
if(this.time > other.time){
return true;
}
return false;
}
public static void main(String[] args) {
Competitor[] tab = new Competitor[100];
tab[0] = new Competitor(1, 45, 15, 20);
tab[1] = new Competitor(1, 45, 12, 45);
tab[2] = new Competitor(5, 12, 13, 59);
tab[3] = new Competitor(12, 12, 15, 70);
tab[4] = new Competitor(32, 75, 15, 20);
for(int i = 0; i< tab.length; ++i) {
if(tab[i] != null) {
System.out.println(tab[i].display());
System.out.println(tab[0].isFaster(tab[i]));
}
}
}
}
import java.util.Random;
public class Dice {
private int numberSides;
private static final Random RAND = new Random();
private int value;
// Constructeur
public Dice(int numberSides){
if (numberSides > 0){
this.numberSides = numberSides;
}else {
this.numberSides = 1;
}
}
// Méthodes
public void roll(){
this.value = this.RAND.nextInt(numberSides)+1;
}
public String toString(int value) {
return "Le dé a fait " + value;
}
public int getValue() {
return this.value;
}
}
public class DicePlayer {
private String name;
private int totalValue;
private int nbDiceRolls;
// Constructeur
DicePlayer(String name){
this.name = name;
}
// Méthodes
public void play(Dice dice6){
dice6.roll();
this.totalValue = this.totalValue + dice6.getValue();
++this.nbDiceRolls;
}
public String toString() {
return this.name + ": " + this.totalValue + " points en " + this.nbDiceRolls + " coups.";
}
}
public class NDicePlayerGame {
private DicePlayer[] players;
public NDicePlayerGame(int numPlayers) {
this.players = new DicePlayer[numPlayers];
for (int i = 0; i < numPlayers; i++) {
players[i] = new DicePlayer(String.valueOf(i));
}
}
public DicePlayer[] winner() {
int minRolls = Integer.MAX_VALUE;
int countWinners = 0;
for (DicePlayer player : players) {
if (player.nbDiceRolls < minRolls) {
minRolls = player.nbDiceRolls;
countWinners = 1;
} else if (player.nbDiceRolls == minRolls) {
countWinners++;
}
}
DicePlayer[] winners = new DicePlayer[countWinners];
int index = 0;
for (DicePlayer player : players) {
if (player.nbDiceRolls == minRolls) {
winners[index++] = player;
}
}
return winners;
}
public static void main(String[] args) {
int numPlayers = Integer.parseInt(args[0]);
NDicePlayerGame game = new NDicePlayerGame(numPlayers);
Dice dice = new Dice(6);
for (DicePlayer player : game.players) {
while (player.totalValue < 20) {
player.play(dice);
}
}
System.out.println("Les vainqueurs:");
for (DicePlayer winner : game.winner()) {
System.out.println(winner.name + ": " + winner.totalValue + " points en " + winner.nbDiceRolls + " coups.");
}
}
}
//Hugo DEBUYSER
public class OneDicePlayerGame {
public static void main(String[] args) {
Dice de = new Dice(6);
DicePlayer j1 = new DicePlayer("Hugo");
System.out.println(j1.toString());
while(j1.higherThan(20) == false){
j1.play(de);
System.out.println(j1.toString());
}
}
}
//Hugo DEBUYSER
public class TwoDicePlayerGame {
private DicePlayer player1;
private DicePlayer player2;
public TwoDicePlayerGame(DicePlayer player1, DicePlayer player2) {
this.player1 = player1;
this.player2 = player2;
}
public DicePlayer winner() {
if (player1.isWinning(player2)) {
return player1;
} else {
return player2;
}
}
public static void main(String[] args) {
DicePlayer alice = new DicePlayer("Alice");
DicePlayer bob = new DicePlayer("Bob");
TwoDicePlayerGame game = new TwoDicePlayerGame(alice, bob);
Dice dice = new Dice(6);
while (alice.totalValue < 20 && bob.totalValue < 20) {
alice.play(dice);
bob.play(dice);
}
System.out.println("Le gagnant est " + game.winner());
}
}
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.isFaster(bruno));
System.out.println("Alice:" + alice.display() + " null:" + null + "->" + alice.isFaster(null));
System.out.println("Alice:" + alice.display() + " Alice:" + alice.display() + "->" + alice.isFaster(alice));
System.out.println("Alice:" + alice.display() + " Clement:" + clement.display() + "->" + alice.isFaster(clement));
System.out.println("Clement:" + clement.display() + " Dora:" + dora.display() + "->" + clement.isFaster(dora));
}
}
public enum Color {
CLUB, DIAMOND, HEART, SPADE;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment