Skip to content
Snippets Groups Projects
Commit fa60704a authored by samuel turpin's avatar samuel turpin
Browse files

add all files

parent a8ab7946
No related branches found
No related tags found
No related merge requests found
Showing
with 321 additions and 0 deletions
File added
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
File added
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;
}
}
File added
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]);
}
}
}
File added
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
File added
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
File added
/* 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
File added
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);
}
}
File added
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
File added
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
File added
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment