Skip to content
Snippets Groups Projects
Commit 63f3c434 authored by BAUER Oscar's avatar BAUER Oscar
Browse files

snake branch

parent fe2d0c29
No related branches found
No related tags found
No related merge requests found
package td14.exo1;
public class BisectionUtils {
/* Fonction f(x) = x * x - 4 */
static double f(double x) {
return x * x - 4;
}
/* Mthode de dichotomie (on suppose que f(a) et f(b) sont de signes opposs) */
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;
}
/* Itrations 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;
}
}
package td14.exo1;
public class BisectionUtilsTest {
public static void main(String[] args) {
double result = BisectionUtils.findZero(0, 4, 1e-12);
System.out.println(result);
}
}
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()]);
}
}
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];
}
}
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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment