Skip to content

Commit

Permalink
Update 23/05 21:55
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo committed May 23, 2022
1 parent e948f28 commit b3238fe
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 9 deletions.
Binary file modified bin/fr/programme/com/Programme.class
Binary file not shown.
Binary file modified bin/src/Account2.class
Binary file not shown.
Binary file modified bin/src/User$UserBuilder.class
Binary file not shown.
Binary file modified bin/src/User.class
Binary file not shown.
47 changes: 46 additions & 1 deletion src/fr/programme/com/Programme.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.programme.com;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
Expand Down Expand Up @@ -115,7 +116,7 @@ public static void main(String[] args){
Account<String> otherAccount = new Account<String>("Bob", 200, " euros");
otherAccount.showBalance();

Bank bank = new Bank("Ric&CieBank");
Bank bank = new Bank("Bank");
bank.transfert(myAccount, otherAccount, 25);
bank.transfert(otherAccount, myAccount, 25);
Compare.Compare();
Expand Down Expand Up @@ -215,6 +216,50 @@ public static void main(String[] args){
Tableaux.Tableaux();
Characters.Characters();
ChainesDeCaracteres.ChainesDeCaracteres();
Personnage test1 = new Personnage(15,167,"Riccardo");
CatTP testtkt = new CatTPBuilder()
.withAge(2)
.withIsSterilised(true)
.withName("Carla")
.withOwner("Karine ROUX")
.build();
System.out.println(testtkt.getAge());
Personnage deBase = new Personnage();
Account2<String> testjspmaistkt = new Account2<String>("Ric", 0, " euros");
System.out.println("--------------------------------");
for(Account2<String> i : Account2.getListOfAccountsTypeString()) {
System.out.println(i.getOwner());
}
System.out.println("--------------------------------");
// System.out.println(Account2.getListOfAccountsTypeString().get(0).getOwner());
Account2<String> testjsppkmaistkt = new Account2<String>("Riccardo", 1000, " euros");
System.out.println(testjsppkmaistkt.getOwner());
testjsppkmaistkt.setNameBecauseIncorect("Ric");
System.out.println(testjsppkmaistkt.getOwner());
testjsppkmaistkt.setNameBecauseIncorect("Ric2.0");
System.out.println(testjsppkmaistkt.getOwner());
PersoSwag persoSwag = new PersoSwag();
System.out.println(testjsppkmaistkt.getAmount());
System.out.println(riccardo.getAmount());
testjsppkmaistkt.transfertMoneyToOwner("Riccardo", -1);
System.out.println(testjsppkmaistkt.getAmount());
System.out.println(riccardo.getAmount());
}
public static class Personnage{
private int age;
private int taille;
private String name;
//Constructeur
public Personnage(int age, int taille, String name) {
this.age = age;
this.taille = taille;
this.name = name;

System.out.println(this.age+" - "+this.taille+" - "+this.name);
}
public Personnage() {
this(15,175,"Riccardo");
}
}
// public static void startTimer() {
// startTimer2 = true;
Expand Down
87 changes: 86 additions & 1 deletion src/src/Account2.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
package src;

import java.util.ArrayList;

public class Account2<T> {
private String owner;
private int amount;
private T currency;
private static ArrayList<String> listOfAccountsNames = new ArrayList();
private static ArrayList<Account2<String>> listOfAccountsTypeString = new ArrayList<Account2<String>>();
private static ArrayList<Account2<Character>> listOfAccountsTypeChar = new ArrayList<Account2<Character>>();
private static boolean NameIsValid(String owner) {
boolean isValid = true;
if(owner==null) {
isValid = false;
return isValid;
}
for(Account2<String> i : Account2.getListOfAccountsTypeString()) {
if(i.getOwner().equals(owner)) {
isValid = false;
}
}
return isValid;
}
public Account2(String owner, int amount, T currency){
this.owner = owner;
if(NameIsValid(owner)) {
listOfAccountsNames.add(owner);
if(currency.getClass()==char.class) {
listOfAccountsTypeChar.add((Account2<Character>) this);
this.owner = owner;
} else {
listOfAccountsTypeString.add((Account2<String>) this);
this.owner = owner;
}
} else {
this.owner = null;
System.out.println("Vous ne pouvez pas vous appelez "+owner+" car une autre personne possède déjà ce nom ! Vous pouvez le définir en faisant compte.setNameBecauseIncorect(\"nom\")");
}
// if (listOfAccountsTypeChar.size()>0) {
// System.out.println(listOfAccountsTypeChar.get(listOfAccountsTypeChar.size()-1));
// System.out.println(listOfAccountsTypeString.get(listOfAccountsTypeString.size()-1));
// }
this.amount = amount;
this.currency = currency;
}
Expand All @@ -19,6 +53,10 @@ public T getCurrency() {
return currency;
}
public void transfertMoneyTo(Account2 targetAccount, int amount) {
if(amount<=0) {
System.out.println("Bien essayé mais non !");
return;
}
if(this.getAmount()>=amount) {
this.amount-=amount;
targetAccount.amount+=amount;
Expand All @@ -27,4 +65,51 @@ public void transfertMoneyTo(Account2 targetAccount, int amount) {
System.out.println(this.getOwner()+"n'a pas assez d'argent pour envoyer "+amount+this.currency+" à "+targetAccount.getOwner());
}
}
public static ArrayList<Account2<String>> getListOfAccountsTypeString(){
return listOfAccountsTypeString;
}
public static ArrayList<Account2<Character>> getListOfAccountsTypeChar(){
return listOfAccountsTypeChar;
}
public void setNameBecauseIncorect(String owner) {
if(!NameIsValid(this.owner)) {
if(NameIsValid(owner)) {
listOfAccountsNames.add(owner);
if(currency.getClass()==char.class) {
listOfAccountsTypeChar.add((Account2<Character>) this);
this.owner = owner;
} else {
listOfAccountsTypeString.add((Account2<String>) this);
this.owner = owner;
}
} else {
this.owner = null;
System.out.println("Vous ne pouvez pas vous appelez "+owner+" car une autre personne possède déjà ce nom ! Vous pouvez le définir en faisant compte.setNameBecauseIncorect(\"nom\")");
}
}
}
public void transfertMoneyToOwner(String name, int amount) {
Account2 targetAccount = null;
if(amount<=0) {
System.out.println("Bien essayé mais non !");
return;
}
if(this.getAmount()>=amount) {
for(Account2<String> i : Account2.getListOfAccountsTypeString()) {
if(i.getOwner().equals(name)) {
targetAccount = i;
}
}
} else {
System.out.println("Pas assez d'argent !");
return;
}
if(targetAccount == null) {
System.out.println(name+" account not found !");
return;
}
this.amount -= amount;
targetAccount.amount += amount;
System.out.println(amount+""+this.currency+" ont été envoyés de "+this.getOwner()+" à "+targetAccount.getOwner());
}
}
32 changes: 32 additions & 0 deletions src/src/CatTP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package src;

public class CatTP {
private String name;
private int age;
private String owner;
private boolean isSterilised;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public boolean isSterilised() {
return isSterilised;
}
public void setSterilised(boolean isSterilised) {
this.isSterilised = isSterilised;
}
}
32 changes: 32 additions & 0 deletions src/src/CatTPBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package src;

public class CatTPBuilder {
private String name;
private int age;
private String owner;
private boolean isSterilised;
public CatTPBuilder withName(String name) {
this.name = name;
return this;
}
public CatTPBuilder withAge(int age) {
this.age = age;
return this;
}
public CatTPBuilder withOwner(String owner) {
this.owner = owner;
return this;
}
public CatTPBuilder withIsSterilised(boolean isSterilised) {
this.isSterilised = isSterilised;
return this;
}
public CatTP build() {
CatTP cat2 = new CatTP();
cat2.setName(name);
cat2.setAge(age);
cat2.setOwner(owner);
cat2.setSterilised(isSterilised);
return cat2;
}
}
31 changes: 31 additions & 0 deletions src/src/ChainesDeCaracteres.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package src;

import java.util.Arrays;

public class ChainesDeCaracteres {
public static void ChainesDeCaracteres() {
String str = "idk";
Expand All @@ -8,5 +10,34 @@ public static void ChainesDeCaracteres() {
System.out.println(str.compareTo("idl") < 0 ? "C'est la même chose !" : "Ce n'est pas la même chose !");
System.out.println("ba".compareTo("baaaa")); //=> -3 car trois caractères identiques en moins
System.out.println(str.length());
System.out.println(str.toUpperCase());
String[] array = {"ggggf","sdfsfd","fddfsd"};
Arrays.sort(array);
System.out.println(array[0]);System.out.println(array[1]);System.out.println(array[2]);
String numberString = "1516";
int number = Integer.valueOf(numberString); //ou parseInt(str1) c'est pareil
String numberToString = String.valueOf(number);
System.out.println(numberToString);
StringBuffer sB = new StringBuffer(str);
sB.setCharAt(0, '[');
System.out.println(sB.toString());
String trimExemple = " aaa ";
System.out.println(trimExemple.trim()); //supprime les espaces aux extrémités
trimExemple = trimExemple.replace('a', '#');
System.out.println(trimExemple);
trimExemple = trimExemple.replaceAll("###", "test");
System.out.println(trimExemple);
StringBuilder sb = new StringBuilder("");
for(int i = 0;i<10;i++) {
sb.append("a");
}
System.out.println(sb.toString());

String text = "Ceci est une phrase XD";

System.out.println();
for(String j : text.split(" ")) {
System.out.println(j);
}
}
}
7 changes: 7 additions & 0 deletions src/src/Objets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package src;

public class Objets {
public Objets() {

}
}
11 changes: 11 additions & 0 deletions src/src/PersoSwag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package src;

import fr.programme.com.Programme.Personnage;

public class PersoSwag extends Personnage{
private int badass;

public PersoSwag() {
super(15,200,"PersoSwag");
}
}
7 changes: 0 additions & 7 deletions src/src/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ public class User {
private String phone;
private String address;

// public User(String lastName, String firstName, String phone, String address) {
// this.lastName = lastName;
// this.firstName = firstName;
// this.phone = phone;
// this.address = address;
// }

public static class UserBuilder{
private String lastName = "<non défini>";
private String firstName = "<non défini>";
Expand Down

0 comments on commit b3238fe

Please sign in to comment.