Skip to content
Snippets Groups Projects
Commit cbd80d54 authored by Alexandre MAINTIER's avatar Alexandre MAINTIER
Browse files

initialisation

parent a9ccfd76
Branches
No related tags found
No related merge requests found
Showing
with 416 additions and 0 deletions
*.class
*.sh
bin/
docs/
\ No newline at end of file
[submodule "dev-qu"]
path = dev-qu
url = git@gitlab-ssh.univ-lille.fr:alexandre.maintier.etu/dev-qu.git
File added
File added
class Book{
String author;
String title;
int year;
Book(String author, String title, int year){
this.author = author;
this.title = title;
this.year = year;
}
public String toString(){
return this.author + ";" + this.title + ";" + this.year;
}
boolean isOldest(Book book){
if(this.year<book.year){
return true;
}
return false;
}
}
\ No newline at end of file
class HighScore{
Score[] top;
HighScore(){
top = new Score[100];
}
HighScore(int taille){
top = new Score[taille];
}
int getNbFreeSlot(){
int resultat = 0;
for(int i = 0; i<this.top.length; i++){
if(this.top[i]==null){
resultat++;
}
}
return resultat;
}
public String toString(){
String resultat = ("TOP SCORES : \n");
for(int i=0; i<this.top.length-this.getNbFreeSlot(); i++){
resultat = resultat + this.top[i].toString() + "\n";
}
resultat = resultat + "**" + this.getNbFreeSlot() + "** free slots";
return resultat;
}
}
\ No newline at end of file
class Score{
String name;
int score;
String timestamp;
Score(String name, int score, String timestamp){
this.name = name;
this.score = score;
this.timestamp = timestamp;
}
public String toString(){
return "(" + this.timestamp + ") " + this.name + " = " + this.score;
}
}
\ No newline at end of file
class UseBook{
public static void main(String args[]){
Book book = new Book("chapeau", "pointu", 1992);
System.out.println(book);
}
}
\ No newline at end of file
class UseBook2{
public static void main(String[] args){
Book book1 = new Book("chapeau", "pointu", 1992);
Book book2 = new Book("chapeau", " plus pointu", 1993);
Book book3 = new Book("chapeau", " encore pointu", 1994);
Book book4 = new Book("chapeau", "toujours plus pointu", 1995);
Book book5 = new Book("chapeau", "le plus pointu", 1996);
Book[] bibli = new Book[]{book1,book2,book3,book4,book5};
Book vieux = bibli[0];
for(int i = 0; i<bibli.length;i++){
System.out.println(bibli[i]);
if(i<bibli.length-1){
if(bibli[i+1].isOldest((bibli[i]))){
vieux = bibli[i+1];
}
}
}
System.out.println("le plus vieux est : " + vieux);
}
}
\ No newline at end of file
class Competitor{
String numberSign;
int time;
int score;
Competitor(int min, int sec, int numberSign, int score){
if(numberSign>=0 && numberSign <=100){
this.numberSign = "No" + numberSign;
}
this.time = 60*min + sec;
this.score = score;
}
public String toString(){
String number;
if(this.numberSign == null){
number = "-invalide-";
}
else{
number = this.numberSign;
}
return number + ", " + this.score + " points, " + this.time + " s";
}
boolean equals(Competitor other){
if(other == null){
return false;
}
if(this.numberSign == null || other.numberSign == null){
if(this.numberSign != other.numberSign){
return false;
}
}
if(this.numberSign.equals(other.numberSign) && this.score == other.score && this.time == other.time){
return true;
}
return false;
}
boolean isFaster(Competitor other){
if(this.time<other.time){
return true;
}
return false;
}
}
\ No newline at end of file
public class UseCompetitor2 {
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);
Competitor reference = new Competitor(2,2,13,50);
System.out.println("Alice:" + alice + " Bruno:" + bruno + "->" + 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 plus rapide que reference : " + alice.time + "vs" + reference.time + "->" + alice.isFaster(reference));
System.out.println("Bruno plus rapide que reference : " + bruno.time + "vs" + reference.time + "->" + bruno.isFaster(reference));
System.out.println("Clement plus rapide que reference : " + clement.time + "vs" + reference.time + "->" + clement.isFaster(reference));
System.out.println("Dora plus rapide que reference : " + dora.time + "vs" + reference.time + "->" + dora.isFaster(reference));
}
}
\ No newline at end of file
package tp03;
public class Card{
Color color;
Rank rank;
Card(Color color, Rank rank){
this.color=color;
this.rank=rank;
}
Card(String color, String rank){
this.color = Color.valueOf(color);
this.rank = Rank.valueOf(rank);
}
Color getColor(){
return this.color;
}
Rank getRank(){
return this.rank;
}
Boolean equals(Card other){
if(this.color == other.color && this.rank == other.rank){
return true;
}
return false;
}
public String toString(){
return "couleur = " + this.color + ", rang = " + rank;
}
}
\ No newline at end of file
package tp03;
public enum Color {
CLUB, DIAMOND, HEART, SPADE;
}
\ No newline at end of file
package tp03;
public enum Rank {
SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE;
}
\ No newline at end of file
package tp03;
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");
}
}
File added
package tp04;
public class Person{
private int id;
private String forename;
private String name;
Person(int id, String forename, String name){
this.id = id;
this.forename = forename;
this.name = name;
}
Person(String forename, String name){
this.id = 0;
this.forename = forename;
this.name = name;
}
public int getId(){
return this.id;
}
public String getForename(){
return this.forename;
}
public String getName(){
return this.name;
}
public void setForename(String forename){
this.forename = forename;
}
public void setName(String name){
this.name = name;
}
public String toString(){
return "<" + this.id + "> : <" + this.forename + "> <" + name+ ">";
}
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(this.getClass() != obj.getClass()){
return false;
}
Person other = (Person) obj;
if(this.id != other.id){
return false;
}
if (this.name == null) {
if (other.name != null){
return false;
}
} else if (!this.name.equals(other.name)){
return false;
}
if (this.forename == null) {
if (other.forename != null){
return false;
}
} else if (!this.forename.equals(other.forename)){
return false;
}
return true;
}
}
\ No newline at end of file
package tp04;
class Student{
Person pers;
double[] grades = new double[4];
Student(Person pers, double[] grades){
this.pers = pers;
this.grades = grades;
}
Student(String name, String forename, double[] grades){
this.pers = new Person(forename, name);
this.grades = grades;
}
Student(String name, String forename, double grade){
this.pers = new Person(forename, name);
this.grades[0] = grade;
}
}
\ No newline at end of file
package tp04;
public class UsePerson {
public static void main(String[] args) {
Person alice = new Person("Alice", "A");
Person bruno = new Person("Bruno", "B");
Person autre = alice;
boolean testsOK = true;
// test des getters
if(!alice.getForename().equals("Alice") || !alice.getName().equals("A") || !bruno.getForename().equals("Bruno") || !bruno.getName().equals("B") || !autre.getForename().equals("Alice") || !autre.getName().equals("A")) {
System.out.println("Erreur de méthodes GET");
testsOK = false;
}
// test des setters
alice.setForename("Anatole");
bruno.setName("BB");
if(!alice.getForename().equals("Anatole") || !alice.getName().equals("A") || !bruno.getForename().equals("Bruno") || !bruno.getName().equals("BB") || !autre.getForename().equals("Anatole") || !autre.getName().equals("A")) {
System.out.println("Erreur de méthodes SET");
testsOK = false;
}
// test du equals
if(alice.equals(bruno) || !alice.equals(autre)) {
System.out.println("Erreur de méthode equals");
testsOK = false;
}
if(testsOK) System.out.println("Tests de UsePerson réussis !");
}
}
package tp06;
import java.util.ArrayList;
import java.time.LocalDate;
public class Company{
private ArrayList<Employee> staff = new ArrayList<>();
public void addEmployee(Employee employe){
staff.add(employe);
}
public void removeEmployee(int id){
staff.remove(id);
}
public void removeEmployee(Employee employe){
staff.remove(employe);
}
public String toString(){
return "give us your soul";
}
public int getNbEmployee(){
return staff.size();
}
public int getNbWorker(){
int resultat = 0;
for(int i = 0; i<staff.size(); i++){
if(staff.get(i).getTitle() == "Travailleur"){
resultat ++;
}
}
return resultat;
}
public int getNbSalesPerson(){
int resultat = 0;
for(int i = 0; i<staff.size(); i++){
if(staff.get(i).getTitle() == "Vendeur"){
resultat ++;
}
}
return resultat;
}
public void firing(LocalDate fatefulDate){
ArrayList<Employee> vire = new ArrayList<>();
for(int i = 0; i<staff.size(); i++){
if(fatefulDate.isBefore(staff.get(i).getHiringDate())){
vire.add(staff.get(i));
}
}
staff.removeAll(vire);
}
public void firing(){
ArrayList<Employee> vire = new ArrayList<>();
for(int i = 0; i<staff.size(); i++){
if(!staff.get(i).objectiveFulfilled()){
vire.add(staff.get(i));
}
}
staff.removeAll(vire);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment