diff --git a/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtils.java b/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..d35dad1f7408315879a884a84efd4a53c1b73d0d --- /dev/null +++ b/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtils.java @@ -0,0 +1,29 @@ +package td14.exo1; + +public class BisectionUtils { + /* Fonction f(x) = x * x - 4 */ + static double f(double x) { + return x * x - 4; + } + + /* M�thode de dichotomie (on suppose que f(a) et f(b) sont de signes oppos�s) */ + static double findZero(double a, double b, double epsilon) { + /* Si f(a) >= 0, on �change a et b */ + if (f(a) > 0) { + double temp = a; + a = b; + b = temp; + } + /* It�rations jusqu'� |a - b| <= epsilon */ + while (Math.abs(b - a) > epsilon) { + double mid = (a + b) / 2; + if (f(mid) < 0) { + a = mid; + } else { + b = mid; + } + } + /* Lorsque |a - b| <= epsilon, on retourne une valeur entre a et b */ + return (a + b) / 2; + } +} diff --git a/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtilsTest.java b/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtilsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2136bc86bcc63209d67adfc67ca13ee445173fa1 --- /dev/null +++ b/CCI_Java/CCI_Java/src/td14/exo1/BisectionUtilsTest.java @@ -0,0 +1,11 @@ +package td14.exo1; + +public class BisectionUtilsTest { + + public static void main(String[] args) { + double result = BisectionUtils.findZero(0, 4, 1e-12); + System.out.println(result); + + } + +} diff --git a/CCI_Java/CCI_Java/src/td15/exo1/Member.java b/CCI_Java/CCI_Java/src/td15/exo1/Member.java new file mode 100644 index 0000000000000000000000000000000000000000..ad39ad9516626074aa390925b81ad86544fd5e01 --- /dev/null +++ b/CCI_Java/CCI_Java/src/td15/exo1/Member.java @@ -0,0 +1,49 @@ +package td15.exo1; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Member { + private String firstName; + private String lastName; + private boolean[] practicedSports; + + public Member(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + practicedSports = new boolean[Sports.TOTAL_SPORTS]; + for (int idx = 0; idx < Sports.TOTAL_SPORTS; idx++) { + practicedSports[idx] = false; + } + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public boolean practices(int sport) { + return practicedSports[sport]; + } + + public void addSport(int sport) { + practicedSports[sport] = true; + } + + public void removeSport(int sport) { + practicedSports[sport] = false; + } + + public int[] getPracticedSports() { + List<Integer> resList = new ArrayList<Integer>(); + for (int idx = 0; idx < Sports.TOTAL_SPORTS; idx++) { + if(practicedSports[idx]) + resList.add(idx); + } + returns resList.toArray(new int[resList.size()]); + } +} diff --git a/CCI_Java/CCI_Java/src/td15/exo1/Sports.java b/CCI_Java/CCI_Java/src/td15/exo1/Sports.java new file mode 100644 index 0000000000000000000000000000000000000000..c62343e10945d01827f4b1fa7b051a03290fa481 --- /dev/null +++ b/CCI_Java/CCI_Java/src/td15/exo1/Sports.java @@ -0,0 +1,19 @@ +package td15.exo1; + +public class Sports { + public static final int TENNIS = 0; + public static final int NATATION = 1; + public static final int ATHLETISME = 2; + public static final int VOLLEY = 3; + public static final int RUGBY = 4; + public static final int BASKET = 5; + public static final int RANDONNEE = 6; + private static final String[] list = { "Tennis", "Swimming", "Athletics", "Volleyball", "Rugby", "Basket", + "Hiking" }; + + public static int TOTAL_SPORTS = 7; + + public static String getName(int sport) { + return list[sport]; + } +} diff --git a/CCI_Java/CCI_Java/src/td15/exo1/TestSports.java b/CCI_Java/CCI_Java/src/td15/exo1/TestSports.java new file mode 100644 index 0000000000000000000000000000000000000000..f60bf7e25860f81819ab378c4b2cf50d5e020e51 --- /dev/null +++ b/CCI_Java/CCI_Java/src/td15/exo1/TestSports.java @@ -0,0 +1,15 @@ +package td15.exo1; + +public class TestSports { + + public static void main(String[] args) { + // TODO Auto-generated method stub + System.out.println("Affichage de deux sports particuliers :"); + System.out.println(Sports.getName(Sports.RUGBY)); + System.out.println(Sports.getName(Sports.TENNIS)); + System.out.println("Affichage de tous les sports :"); + for (int sport = 0; sport < Sports.TOTAL_SPORTS; sport++) + System.out.println(Sports.getName(sport)); + } + +}