master
This commit is contained in:
BIN
src/POO/T0_introduction/7_00-introduction.mp4
Normal file
BIN
src/POO/T0_introduction/7_00-introduction.mp4
Normal file
Binary file not shown.
BIN
src/POO/T0_introduction/7_01-exemple_de_code.mp4
Normal file
BIN
src/POO/T0_introduction/7_01-exemple_de_code.mp4
Normal file
Binary file not shown.
BIN
src/POO/T0_introduction/7_classes_et_objets.pdf
Normal file
BIN
src/POO/T0_introduction/7_classes_et_objets.pdf
Normal file
Binary file not shown.
10
src/POO/T0_introduction/Rectangle.java
Normal file
10
src/POO/T0_introduction/Rectangle.java
Normal file
@ -0,0 +1,10 @@
|
||||
package POO.T0_introduction;
|
||||
|
||||
public class Rectangle {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public int area() {
|
||||
return width * height;
|
||||
}
|
||||
}
|
25
src/POO/T0_introduction/RectangleDemoBegin.java
Normal file
25
src/POO/T0_introduction/RectangleDemoBegin.java
Normal file
@ -0,0 +1,25 @@
|
||||
package POO.T0_introduction;
|
||||
|
||||
public class RectangleDemoBegin {
|
||||
|
||||
public static void main(String args[]) {
|
||||
Rectangle r1 = new Rectangle();
|
||||
r1.height = 4;
|
||||
r1.width = 4;
|
||||
|
||||
Rectangle r2 = new Rectangle();
|
||||
r2.height = 5;
|
||||
r2.width = 6;
|
||||
|
||||
Rectangle r3 = new Rectangle();
|
||||
r3.height = 2;
|
||||
r3.width = 2;
|
||||
|
||||
int totalArea = r1.area();
|
||||
totalArea += r2.area();
|
||||
totalArea += r3.area();
|
||||
|
||||
System.out.println(totalArea);
|
||||
|
||||
}
|
||||
}
|
BIN
src/POO/T1_classes_et_objets/7_1-classes_et_objets.pdf
Normal file
BIN
src/POO/T1_classes_et_objets/7_1-classes_et_objets.pdf
Normal file
Binary file not shown.
BIN
src/POO/T1_classes_et_objets/7_11-classes_et_objets.mp4
Normal file
BIN
src/POO/T1_classes_et_objets/7_11-classes_et_objets.mp4
Normal file
Binary file not shown.
BIN
src/POO/T1_classes_et_objets/7_12-objets_vs_variables.mp4
Normal file
BIN
src/POO/T1_classes_et_objets/7_12-objets_vs_variables.mp4
Normal file
Binary file not shown.
17
src/POO/T1_classes_et_objets/Car.java
Normal file
17
src/POO/T1_classes_et_objets/Car.java
Normal file
@ -0,0 +1,17 @@
|
||||
package POO.T1_classes_et_objets;
|
||||
|
||||
public class Car {
|
||||
String color = "";
|
||||
String type = "";
|
||||
int maxSpeed;
|
||||
|
||||
public String getStringRepresentation() {
|
||||
String s = type;
|
||||
s += " ";
|
||||
s += color;
|
||||
s += ", vitesse max: ";
|
||||
s += maxSpeed;
|
||||
s += "km/h";
|
||||
return s;
|
||||
}
|
||||
}
|
16
src/POO/T1_classes_et_objets/Ex1–La_classe_Person.txt
Normal file
16
src/POO/T1_classes_et_objets/Ex1–La_classe_Person.txt
Normal file
@ -0,0 +1,16 @@
|
||||
Objectifs
|
||||
Créer une classe
|
||||
Tester la classe
|
||||
Enoncé du problème
|
||||
Nous souhaitons créer une classe devant représenter une personne. Une personne possède les attributs suivants :
|
||||
Nom
|
||||
Prénom
|
||||
Âge
|
||||
Taille
|
||||
|
||||
Travail à faire
|
||||
Créer la classe Person avec les attributs nécessaires
|
||||
Dans une autre classe qui contiendra votre main :
|
||||
Instanciez une première personne de 19 ans, nommée "John Doe", mesurant 1.75 m
|
||||
Instanciez une second personne de 122 ans, nommée "Mathusalem", dont la taille est de 1.20 m
|
||||
Vérifiez que tout fonctionne bien avec ces deux objets. Notamment, essayez d’imprimer le nom des personnes lorsque vous les aurez instanciées.
|
23
src/POO/T1_classes_et_objets/Ex2–La_classe_Car.txt
Normal file
23
src/POO/T1_classes_et_objets/Ex2–La_classe_Car.txt
Normal file
@ -0,0 +1,23 @@
|
||||
Objectifs
|
||||
Créer une classe
|
||||
Tester une classe
|
||||
Tester les méthodes de classes existantes (avec la classe String)
|
||||
Enoncé du problème
|
||||
On souhaite réaliser une classe pour modéliser une voiture. Pensez quels types d’attributs cette classe doit posséder, sachant
|
||||
Un véhicule est caractérisé par sa couleur, son nom et sa vitesse maximale.
|
||||
Un véhicule possède une méthode permettant de retourner sa représentation textuelle. Par exemple le code suivant :
|
||||
|
||||
Car c1 = new Car();
|
||||
c1.color = "bleue";
|
||||
c1.maxSpeed = 250;
|
||||
c1.type = "Ford Raptor";
|
||||
System.out.println(c1.getStringRepresentation());
|
||||
|
||||
doit afficher
|
||||
|
||||
Ford Raptor bleue, vitesse max : 250 km/h
|
||||
|
||||
Travail à faire
|
||||
Implémentez la classe Car selon les instructions ci-dessus.
|
||||
Testez votre classe Car dans une autre classe qui contiendra le main.
|
||||
Vérifiez que l’affichage est bien correct.
|
13
src/POO/T1_classes_et_objets/Exercice2.java
Normal file
13
src/POO/T1_classes_et_objets/Exercice2.java
Normal file
@ -0,0 +1,13 @@
|
||||
package POO.T1_classes_et_objets;
|
||||
|
||||
public class Exercice2 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Car c1 = new Car();
|
||||
c1.color = "bleue";
|
||||
c1.maxSpeed = 250;
|
||||
c1.type = "Ford Raptor";
|
||||
System.out.println(c1.getStringRepresentation());
|
||||
|
||||
}
|
||||
}
|
19
src/POO/T1_classes_et_objets/Person.java
Normal file
19
src/POO/T1_classes_et_objets/Person.java
Normal file
@ -0,0 +1,19 @@
|
||||
package POO.T1_classes_et_objets;
|
||||
|
||||
public class Person {
|
||||
String surname; // Nom de famille
|
||||
String name; // Prénom
|
||||
int age; // Âge
|
||||
double height; // Taille
|
||||
|
||||
public void print() {
|
||||
System.out.print(name);
|
||||
System.out.print(" ");
|
||||
System.out.print(surname);
|
||||
System.out.print(", ");
|
||||
System.out.print(age);
|
||||
System.out.print(", ");
|
||||
System.out.print(height);
|
||||
System.out.println("m.");
|
||||
}
|
||||
}
|
24
src/POO/T1_classes_et_objets/exercice1.java
Normal file
24
src/POO/T1_classes_et_objets/exercice1.java
Normal file
@ -0,0 +1,24 @@
|
||||
package POO.T1_classes_et_objets;
|
||||
|
||||
public class exercice1 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Person john;
|
||||
john = new Person();
|
||||
|
||||
john.surname = "Doe";
|
||||
john.name = "John";
|
||||
john.age = 19;
|
||||
john.height = 1.75;
|
||||
|
||||
Person mathusalem = new Person();
|
||||
|
||||
mathusalem.name = "Mathusalem";
|
||||
mathusalem.age = 122;
|
||||
mathusalem.height = 1.2;
|
||||
|
||||
john.print();
|
||||
mathusalem.print();
|
||||
|
||||
}
|
||||
}
|
BIN
src/POO/T2_constructeurs/7_2-constructeurs.pdf
Normal file
BIN
src/POO/T2_constructeurs/7_2-constructeurs.pdf
Normal file
Binary file not shown.
BIN
src/POO/T2_constructeurs/7_2-les_constructeurs.mp4
Normal file
BIN
src/POO/T2_constructeurs/7_2-les_constructeurs.mp4
Normal file
Binary file not shown.
23
src/POO/T2_constructeurs/Car.java
Normal file
23
src/POO/T2_constructeurs/Car.java
Normal file
@ -0,0 +1,23 @@
|
||||
package POO.T2_constructeurs;
|
||||
|
||||
public class Car {
|
||||
String color = "";
|
||||
String type = "";
|
||||
int maxSpeed;
|
||||
|
||||
public Car(String type, String color, int maxSpeed){
|
||||
this.type = type;
|
||||
this.color = color;
|
||||
this.maxSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
public String getStringRepresentation() {
|
||||
String s = type;
|
||||
s += " ";
|
||||
s += color;
|
||||
s += ", vitesse max: ";
|
||||
s += maxSpeed;
|
||||
s += "km/h";
|
||||
return s;
|
||||
}
|
||||
}
|
19
src/POO/T2_constructeurs/Ex3–constructeur1.txt
Normal file
19
src/POO/T2_constructeurs/Ex3–constructeur1.txt
Normal file
@ -0,0 +1,19 @@
|
||||
Objectif
|
||||
Ajouter un constructeur à une classe existante
|
||||
Tester une classe avec son constructeur
|
||||
Enoncé du problème
|
||||
1. Ajoutez à la classe Car définie auparavant un constructeur permettant d’instancier la voiture en une seule ligne de code, avec tous ses attributs comme ci-dessous.
|
||||
2. Utilisez ce constructeur pour créer une instance de la classe.
|
||||
|
||||
Car c1 = new Car("Ford Raptor", "bleue", 250);
|
||||
System.out.println(c1.getStringRepresentation());
|
||||
|
||||
doit afficher
|
||||
|
||||
Ford Raptor bleue, vitesse max : 250 km/h
|
||||
|
||||
|
||||
Travail à faire
|
||||
Modifiez la classe Car selon les instructions ci-dessus.
|
||||
Testez votre classe Car dans une autre classe qui contiendra le main.
|
||||
Vérifiez que l’affichage est bien correct.
|
12
src/POO/T2_constructeurs/Ex4–constructeur2.txt
Normal file
12
src/POO/T2_constructeurs/Ex4–constructeur2.txt
Normal file
@ -0,0 +1,12 @@
|
||||
Objectif
|
||||
Ajouter plusieurs constructeurs à une classe existante
|
||||
Tester une classe avec son constructeur
|
||||
Constater l’existance de null
|
||||
Enoncé du problème
|
||||
Ajoutez deux constructe urs à la class Person définie auparavant.
|
||||
1. Le premier permettant de définir tous les attributs en une fois.
|
||||
2. Un second constructeur ne prenant que le prénom comme argument. Ce constructeur doit appeler le constructeur avec tous les arguments. Pour les String non définis, utilisez la constante null.
|
||||
Travail à faire
|
||||
Complétez la classe Person selon les instructions ci-dessus.
|
||||
Testez votre classe Person dans une autre classe qui contiendra le main.
|
||||
Utilisez le constructeur à un argument pour instancier Mathusalem, qui n’a pas de prénom. Que se passe-t-il lorsque vous essayer d’appeler une méthode sur le prénom de votre objet, par exemple toUpperCase() qui est une méthode définie pour les String ?
|
10
src/POO/T2_constructeurs/Exercice3.java
Normal file
10
src/POO/T2_constructeurs/Exercice3.java
Normal file
@ -0,0 +1,10 @@
|
||||
package POO.T2_constructeurs;
|
||||
|
||||
public class Exercice3 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Car c1 = new Car("Ford Raptor", "bleue", 250);
|
||||
System.out.println(c1.getStringRepresentation());
|
||||
|
||||
}
|
||||
}
|
13
src/POO/T2_constructeurs/Exercice4.java
Normal file
13
src/POO/T2_constructeurs/Exercice4.java
Normal file
@ -0,0 +1,13 @@
|
||||
package POO.T2_constructeurs;
|
||||
|
||||
public class Exercice4 {
|
||||
public static void main(String[] args) {
|
||||
Person john = new Person("John", "Doe", 19, 1.75);
|
||||
john.print();
|
||||
|
||||
Person momo = new Person("Mathusalem");
|
||||
momo.print();
|
||||
momo.surname.toUpperCase();
|
||||
momo.print();;
|
||||
}
|
||||
}
|
30
src/POO/T2_constructeurs/Person.java
Normal file
30
src/POO/T2_constructeurs/Person.java
Normal file
@ -0,0 +1,30 @@
|
||||
package POO.T2_constructeurs;
|
||||
|
||||
public class Person {
|
||||
String surname = ""; // Nom de famille
|
||||
String name = ""; // Prénom
|
||||
int age; // Âge
|
||||
double height; // Taille
|
||||
|
||||
public Person(String name, String surname, int age, double height){
|
||||
this.surname = surname;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Person(String name){
|
||||
this(name, "", 0, 0);
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.print(name);
|
||||
System.out.print(" ");
|
||||
System.out.print(surname);
|
||||
System.out.print(", ");
|
||||
System.out.print(age);
|
||||
System.out.print(", ");
|
||||
System.out.print(height);
|
||||
System.out.println("m.");
|
||||
}
|
||||
}
|
BIN
src/POO/T3_Visibilite_des_membres/7_3-visibilite_des_membres.mp4
Normal file
BIN
src/POO/T3_Visibilite_des_membres/7_3-visibilite_des_membres.mp4
Normal file
Binary file not shown.
BIN
src/POO/T3_Visibilite_des_membres/7_3-visibilite_des_membres.pdf
Normal file
BIN
src/POO/T3_Visibilite_des_membres/7_3-visibilite_des_membres.pdf
Normal file
Binary file not shown.
14
src/POO/T3_Visibilite_des_membres/Exercice5.java
Normal file
14
src/POO/T3_Visibilite_des_membres/Exercice5.java
Normal file
@ -0,0 +1,14 @@
|
||||
package POO.T3_Visibilite_des_membres;
|
||||
|
||||
public class Exercice5 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Triangle t = new Triangle(5, 2);
|
||||
System.out.println(t.computeArea());
|
||||
System.out.println(computeTriangleArea(t));
|
||||
}
|
||||
|
||||
public static double computeTriangleArea(Triangle t){
|
||||
return (t.base*t.hauteur)/2;
|
||||
}
|
||||
}
|
15
src/POO/T3_Visibilite_des_membres/Triangle.java
Normal file
15
src/POO/T3_Visibilite_des_membres/Triangle.java
Normal file
@ -0,0 +1,15 @@
|
||||
package POO.T3_Visibilite_des_membres;
|
||||
|
||||
public class Triangle {
|
||||
double base;
|
||||
double hauteur;
|
||||
|
||||
Triangle(double base, double hauteur){
|
||||
this.base = base;
|
||||
this.hauteur = hauteur;
|
||||
}
|
||||
|
||||
public double computeArea(){
|
||||
return (base*hauteur)/2;
|
||||
}
|
||||
}
|
BIN
src/POO/T4_modificateur_static/7_4-modificateur_static.pdf
Normal file
BIN
src/POO/T4_modificateur_static/7_4-modificateur_static.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/POO/string_methods.pdf
Normal file
BIN
src/POO/string_methods.pdf
Normal file
Binary file not shown.
117
src/dumpThings/dickClock.java
Normal file
117
src/dumpThings/dickClock.java
Normal file
@ -0,0 +1,117 @@
|
||||
package dumpThings;
|
||||
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class dickClock {
|
||||
|
||||
final static int GRAPHICS_WIDTH = 640;
|
||||
final static int GRAPHICS_HEIGHT = 480;
|
||||
final static int STARTING_POSITION_X = 320;
|
||||
final static int STARTING_POSITION_Y = 240;
|
||||
|
||||
// Display surface to draw on
|
||||
public static FunGraphics display;
|
||||
|
||||
public static void fastdrawDisc(int radius, int Cx, int Cy){
|
||||
|
||||
// Draws a red disc
|
||||
for (int x =Cx-radius; x <(radius + Cx); x++){
|
||||
for (int y = Cy-radius; y < (radius + Cy); y++){
|
||||
double distance = (Cx - x) * (Cx - x) + (Cy - y) * (Cy - y);
|
||||
|
||||
if (distance <= radius*radius){
|
||||
display.setPixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawShaft(int Cx, int Cy, int diameter, int length, double angle ){
|
||||
|
||||
int Xx=Cx+(int)((double)((diameter/2.0)*Math.cos(angle*Math.PI/180.0)));
|
||||
int Yy=Cy+(int)((double)((diameter/2.0)*Math.sin(angle*Math.PI/180.0)));
|
||||
|
||||
|
||||
|
||||
int XTop=Xx+(int)(length*Math.cos(angle*Math.PI/180.0-Math.PI/2.0));
|
||||
int YTop=Yy+(int)(length*Math.sin(angle*Math.PI/180.0-Math.PI/2.0));
|
||||
|
||||
for (int j=0;j<diameter;j++) {
|
||||
int a = (int)((double)(j*Math.cos(angle*Math.PI/180.0)));
|
||||
int b = (int)((double)(j*Math.sin(angle*Math.PI/180.0)));
|
||||
display.drawLine(Xx-a, Yy-b,XTop-a,YTop-b );
|
||||
}
|
||||
|
||||
XTop=Cx-(int)((double)((diameter/2.0)*Math.cos(angle*Math.PI/180.0)));
|
||||
YTop=Cy-(int)((double)((diameter/2.0)*Math.sin(angle*Math.PI/180.0)));
|
||||
|
||||
|
||||
for (int k=0; k<length;k++) {
|
||||
int a = (int)((double)(k*Math.cos(angle*Math.PI/180.0+Math.PI/2.0)));
|
||||
int b = (int)((double)(k*Math.sin(angle*Math.PI/180.0+Math.PI/2.0)));
|
||||
|
||||
display.drawLine(Xx-a, Yy-b,XTop-a,YTop-b );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void drawPenis(int Cx, int Cy, double angle, Color c, int ballsize, int length, int diameter) {
|
||||
display.setColor(c);
|
||||
int b=(int)((ballsize-2)*Math.cos((180-angle)*Math.PI/180.0));
|
||||
int a=(int)((ballsize-2)*Math.sin((180-angle)*Math.PI/180.0));
|
||||
int e=(int)(length*Math.cos((90-angle)*Math.PI/180.0));
|
||||
int f=(int)(length*Math.sin((90-angle)*Math.PI/180.0));
|
||||
fastdrawDisc(ballsize, Cx+b, Cy-a);
|
||||
fastdrawDisc(ballsize, Cx-b, Cy+a);
|
||||
fastdrawDisc(diameter/2, Cx+e, Cy-f);
|
||||
drawShaft(Cx, Cy, diameter, length, angle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void wait(int ms){
|
||||
try{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex){
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
display = new FunGraphics(GRAPHICS_WIDTH, GRAPHICS_HEIGHT);
|
||||
double seconds1=0;
|
||||
|
||||
for (int n=0;n<360; n+=30) {
|
||||
drawShaft(STARTING_POSITION_X, STARTING_POSITION_Y, 5, 120, n);
|
||||
}
|
||||
while(true) {
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
int hour = rightNow.get(Calendar.HOUR);
|
||||
int minutes=rightNow.get(Calendar.MINUTE);
|
||||
int secondes=rightNow.get(Calendar.SECOND);
|
||||
|
||||
double Hour=hour;
|
||||
double Minute=minutes;
|
||||
Hour=(Hour+Minute/60)*30;
|
||||
Minute=Minute*6;
|
||||
if(seconds1!=secondes) {
|
||||
display.setColor(Color.WHITE);
|
||||
fastdrawDisc(110, STARTING_POSITION_X, STARTING_POSITION_Y);
|
||||
drawPenis(STARTING_POSITION_X, STARTING_POSITION_Y, Hour, Color.red, 20, 70, 20);
|
||||
drawPenis(STARTING_POSITION_X, STARTING_POSITION_Y, Minute, Color.blue, 15, 100, 15);
|
||||
drawPenis(STARTING_POSITION_X, STARTING_POSITION_Y, secondes*6, Color.pink, 8, 45+secondes, 10);
|
||||
|
||||
}
|
||||
seconds1=secondes;
|
||||
//display.setColor(Color.white);
|
||||
//drawPenis(STARTING_POSITION_X, STARTING_POSITION_Y, i/10.0, Color.WHITE);
|
||||
//fastdrawDisc(120, STARTING_POSITION_X, STARTING_POSITION_Y);
|
||||
}
|
||||
}
|
||||
}
|
23
src/lab1/Fuel.java
Normal file
23
src/lab1/Fuel.java
Normal file
@ -0,0 +1,23 @@
|
||||
package lab1;
|
||||
public class Fuel
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
double litre = 0;
|
||||
double distance = 0;
|
||||
|
||||
|
||||
System.out.println("Calculateur de conssomation d'essence.");
|
||||
|
||||
System.out.print("Veuillez entrer la conssomation moyenne de votre voiture : ");
|
||||
litre = Input.readDouble();
|
||||
|
||||
System.out.print("Veuillez entrer le nombre de kilom<6F>tre parcourus : ");
|
||||
distance = Input.readDouble();
|
||||
|
||||
double consso = 0;
|
||||
consso = litre * (distance/100);
|
||||
|
||||
System.out.println("Votre conssomation a été de " + consso + " litres d'essence");
|
||||
}
|
||||
}
|
74
src/lab1/Input.java
Normal file
74
src/lab1/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab1;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
17
src/lab1/MyProgram.java
Normal file
17
src/lab1/MyProgram.java
Normal file
@ -0,0 +1,17 @@
|
||||
package lab1;
|
||||
public class MyProgram {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Declaration de 2 variables
|
||||
int note1 = 3;
|
||||
int note2 = 5;
|
||||
|
||||
// Faire l'opération
|
||||
double theSum = note1 + note2;
|
||||
double average = theSum/2;
|
||||
|
||||
// Afficher le résultat
|
||||
System.out.print("La moyenne est égal à : ");
|
||||
System.out.println(average);
|
||||
}
|
||||
}
|
37
src/lab1/RoomCalc.java
Normal file
37
src/lab1/RoomCalc.java
Normal file
@ -0,0 +1,37 @@
|
||||
package lab1;
|
||||
public class RoomCalc
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
// Declares three variables to store the dimensions
|
||||
double width = 0;
|
||||
double height = 0;
|
||||
double length = 0;
|
||||
|
||||
/*
|
||||
* For each dimension, display a message,
|
||||
* gets the value from the user
|
||||
* and store the value in the corresponding variable
|
||||
*/
|
||||
System.out.println("Volume calculator, by Rémi Heredero");
|
||||
|
||||
System.out.print("Enter width (m) : ");
|
||||
width = Input.readDouble();
|
||||
|
||||
System.out.print("Enter length (m) : ");
|
||||
length = Input.readDouble();
|
||||
|
||||
System.out.print("Enter height (m) : ");
|
||||
height = Input.readDouble();
|
||||
|
||||
// Perform the computation
|
||||
double vol = 0;
|
||||
vol = width * length * height;
|
||||
|
||||
// Compute the volume and displays it
|
||||
System.out.println("The corresponding volume is " + vol + " m^3 big");
|
||||
System.out.println("The corresponding volume is " + vol/0.00454609 + " gallon");
|
||||
|
||||
System.out.println("Goodbye and thank you");
|
||||
}
|
||||
}
|
42
src/lab1/sphere.java
Normal file
42
src/lab1/sphere.java
Normal file
@ -0,0 +1,42 @@
|
||||
package lab1;
|
||||
public class sphere {
|
||||
public static void main(String args[])
|
||||
{
|
||||
double rayon = 0;
|
||||
double epaisseur = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.print("Veuillez entrer le rayon de la sphère en cm : ");
|
||||
rayon = Input.readDouble();
|
||||
|
||||
System.out.print("Veuillez entrer l'épaisseur de la sphère : ");
|
||||
epaisseur = Input.readDouble();
|
||||
|
||||
double rayonInt = rayon - epaisseur;
|
||||
double volume = 0;
|
||||
double volumeInt = 0;
|
||||
volume = (4*Math.PI*rayon*rayon*rayon)/3;
|
||||
volumeInt = (4*Math.PI*rayonInt*rayonInt*rayonInt)/3;
|
||||
|
||||
System.out.println("Le volume total est de " + volume + " cm3");
|
||||
|
||||
double densite = 0;
|
||||
System.out.print("Veuillez entrer la densité de la matière en g/cm3: ");
|
||||
densite = Input.readDouble();
|
||||
|
||||
double poid = 0;
|
||||
poid = densite*(volume-volumeInt);
|
||||
|
||||
System.out.print("La densité total est de " + poid/volume + " => ");
|
||||
|
||||
if(poid/volume < 1) {
|
||||
System.out.println("L'object flotte");
|
||||
} else {
|
||||
System.out.println("L'object ne flotte pas");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
24
src/lab1/swap.java
Normal file
24
src/lab1/swap.java
Normal file
@ -0,0 +1,24 @@
|
||||
package lab1;
|
||||
|
||||
public class swap
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a = 12;
|
||||
int b = 5;
|
||||
|
||||
|
||||
System.out.println("A: "+a);
|
||||
System.out.println("B: "+b);
|
||||
|
||||
System.out.println("swap...");
|
||||
|
||||
int swap = a;
|
||||
a=b;
|
||||
b=swap;
|
||||
|
||||
System.out.println("A: "+a);
|
||||
System.out.println("B: "+b);
|
||||
|
||||
}
|
||||
}
|
BIN
src/lab2/2-Lab-FR-Datatypes.pdf
Normal file
BIN
src/lab2/2-Lab-FR-Datatypes.pdf
Normal file
Binary file not shown.
74
src/lab2/Input.java
Normal file
74
src/lab2/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab2;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
20
src/lab2/Task1.java
Normal file
20
src/lab2/Task1.java
Normal file
@ -0,0 +1,20 @@
|
||||
package lab2;
|
||||
public class Task1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.print("Veuillez entrer la première valeur: ");
|
||||
int valeur1 = Input.readInt();
|
||||
System.out.print("Veuillez entrer la deuxième valeur: ");
|
||||
int valeur2 = Input.readInt();
|
||||
System.out.print("Veuillez entrer la troisième valeur: ");
|
||||
int valeur3 = Input.readInt();
|
||||
|
||||
int smallest = valeur1 < valeur2 ? valeur1 : valeur2;
|
||||
smallest = smallest < valeur3 ? smallest : valeur3;
|
||||
|
||||
System.out.println("La plus petite valeur est la valeur: "+ smallest);
|
||||
|
||||
}
|
||||
|
||||
}
|
280
src/lab2/TextTools.java
Normal file
280
src/lab2/TextTools.java
Normal file
@ -0,0 +1,280 @@
|
||||
package lab2;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A class with functions to manipulate text strings. Based on
|
||||
* an old <code>TextTools</code> version that hid all the strings
|
||||
* in static variables inside the class. This has all been removed and
|
||||
* now everything is explicit and exposed.
|
||||
*
|
||||
* @author Pierre-Andre Mudry, pandre.mudry@hevs.ch
|
||||
*/
|
||||
|
||||
public class TextTools {
|
||||
/**
|
||||
* Get a line of text from the console.
|
||||
*/
|
||||
public static String readText() {
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(
|
||||
System.in));
|
||||
System.out.print("Enter a text : ");
|
||||
try {
|
||||
return stdin.readLine();
|
||||
} catch (Exception ex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer value from the console. Can read octal and hexadecimal
|
||||
* formats as well
|
||||
*/
|
||||
public static int readInt() {
|
||||
System.out.print("Enter an integer value in decimal, octal or hexadecimal format : ");
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
String s = stdin.readLine();
|
||||
if (s.startsWith("0x") || s.startsWith("0X")) {
|
||||
return Integer.parseInt(s.substring(2), 16);
|
||||
} else if (s.startsWith("0")) {
|
||||
return Integer.parseInt(s.substring(1), 8);
|
||||
} else {
|
||||
return Integer.parseInt(s, 10);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double value from the console.
|
||||
*/
|
||||
public static double readDouble() {
|
||||
System.out.print("Enter a double value : ");
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
return Double.parseDouble(stdin.readLine());
|
||||
} catch (Exception ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a boolean value (true, false) from the console.
|
||||
*/
|
||||
public static boolean readBoolean() {
|
||||
System.out.print("Enter a boolean value : ");
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(
|
||||
System.in));
|
||||
try {
|
||||
return (Boolean.valueOf(stdin.readLine())).booleanValue();
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a char from the console.
|
||||
*/
|
||||
public static char readChar() {
|
||||
System.out.print("Enter a character : ");
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
return stdin.readLine().charAt(0);
|
||||
} catch (Exception ex) {
|
||||
return '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the given string <code>input</code> ...
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String reverse(String input) {
|
||||
String output = new String("");
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
output = output + input.charAt(input.length() - (i + 1));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all of the characters in this String to upper case.
|
||||
*
|
||||
* @param input as string : the given string
|
||||
*/
|
||||
public static String toUpperCase(String input) {
|
||||
return input.toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all of the characters in this String to lower case.
|
||||
*
|
||||
* @param input as string : the given string
|
||||
*/
|
||||
public static String toLowerCase(String input) {
|
||||
return input.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of this String to upper case.
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String capitalize(String input) {
|
||||
String output = String.valueOf(input.charAt(0)).toUpperCase();
|
||||
|
||||
for (int i = 1; i < input.length(); i++) {
|
||||
output = output + input.charAt(i);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts a complete String
|
||||
* @param input
|
||||
* @return the inverted String
|
||||
*/
|
||||
public static String invert(String input){
|
||||
return invert(input, input.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the characters of the input string by group of
|
||||
* <code>number</code> characters
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
* @param number
|
||||
* as int : the number of charaters to invert
|
||||
*/
|
||||
private static String invert(String input, int number) {
|
||||
int i = 0;
|
||||
String output = new String("");
|
||||
|
||||
if (input.length() >= number) {
|
||||
for (i = 0; i <= input.length() - number; i = i + number) {
|
||||
for (int j = number; j > 0; j--) {
|
||||
output = output + input.charAt(i + j - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = input.length(); j > i; j--) {
|
||||
output = output + input.charAt(j - 1);
|
||||
}
|
||||
} else {
|
||||
for (int j = input.length(); j > 0; j--) {
|
||||
output = output + input.charAt(j - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide any vowel in a string
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String deleteVowels(String input) {
|
||||
int ASCII = 0;
|
||||
String output = new String("");
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
ASCII = input.codePointAt(i);
|
||||
if (ASCII == 97 || ASCII == 65 || /* 'a' & 'A' */
|
||||
ASCII == 101 || ASCII == 69 || /* 'e' & 'E' */
|
||||
ASCII == 105 || ASCII == 73 || /* 'i' & 'I' */
|
||||
ASCII == 111 || ASCII == 79 || /* 'o' & 'O' */
|
||||
ASCII == 117 || ASCII == 85 || /* 'u' & 'U' */
|
||||
ASCII == 121 || ASCII == 89 || /* 'y' & 'Y' */
|
||||
(ASCII >= 192 && ASCII <= 207) || (ASCII >= 210 && ASCII <= 214)
|
||||
|| (ASCII >= 217 && ASCII <= 221)
|
||||
|| (ASCII >= 224 && ASCII <= 230)
|
||||
|| (ASCII >= 232 && ASCII <= 239)
|
||||
|| (ASCII >= 242 && ASCII <= 246)
|
||||
|| (ASCII >= 249 && ASCII <= 253) || ASCII == 255) {
|
||||
output = output + " ";
|
||||
} else
|
||||
output = output + input.charAt(i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes each consonant in a string
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String deleteConsonants(String input) {
|
||||
int ASCII = 0;
|
||||
String output = new String("");
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
ASCII = input.codePointAt(i);
|
||||
if (ASCII == 97 || ASCII == 65 || /* 'a' & 'A' */
|
||||
ASCII == 101 || ASCII == 69 || /* 'e' & 'E' */
|
||||
ASCII == 105 || ASCII == 73 || /* 'i' & 'I' */
|
||||
ASCII == 111 || ASCII == 79 || /* 'o' & 'O' */
|
||||
ASCII == 117 || ASCII == 85 || /* 'u' & 'U' */
|
||||
ASCII == 121 || ASCII == 89 || /* 'y' & 'Y' */
|
||||
(ASCII >= 192 && ASCII <= 207) || (ASCII >= 210 && ASCII <= 214)
|
||||
|| (ASCII >= 217 && ASCII <= 221)
|
||||
|| (ASCII >= 224 && ASCII <= 230)
|
||||
|| (ASCII >= 232 && ASCII <= 239)
|
||||
|| (ASCII >= 242 && ASCII <= 246)
|
||||
|| (ASCII >= 249 && ASCII <= 253)
|
||||
|| (ASCII >= 33 && ASCII <= 64)
|
||||
|| (ASCII >= 91 && ASCII <= 96)
|
||||
|| (ASCII >= 123 && ASCII <= 191)
|
||||
|| (ASCII >= 208 && ASCII <= 209)
|
||||
|| (ASCII >= 215 && ASCII <= 216)
|
||||
|| (ASCII >= 222 && ASCII <= 223)
|
||||
|| (ASCII >= 240 && ASCII <= 241)
|
||||
|| (ASCII >= 247 && ASCII <= 248)
|
||||
|| (ASCII >= 254 && ASCII <= 255)) {
|
||||
output = output + input.charAt(i);
|
||||
} else
|
||||
output = output + " ";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a string
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String encrypt(String input) {
|
||||
String output = new String("");
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
output = output + (char) ((input.charAt(i) + 5) % 256);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts an encrypted string
|
||||
*
|
||||
* @param input
|
||||
* as string : the given string
|
||||
*/
|
||||
public static String decrypt(String input) {
|
||||
String output = new String("");
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
output = output + (char) ((input.charAt(i) - 5) % 256);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
11
src/lab2/task2.java
Normal file
11
src/lab2/task2.java
Normal file
@ -0,0 +1,11 @@
|
||||
package lab2;
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
double a,b,c;
|
||||
a = 1;
|
||||
b = 1e+8;
|
||||
c = 1e17;
|
||||
System.out.println(((a+b)*c-b*c)/c);
|
||||
|
||||
}
|
||||
}
|
12
src/lab2/task3.java
Normal file
12
src/lab2/task3.java
Normal file
@ -0,0 +1,12 @@
|
||||
package lab2;
|
||||
|
||||
public class task3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
short toto = (short) (0xFFFFF);
|
||||
System.out.println(toto);
|
||||
toto = (short) (toto + 1);
|
||||
System.out.println(toto);
|
||||
}
|
||||
|
||||
}
|
11
src/lab2/task4.java
Normal file
11
src/lab2/task4.java
Normal file
@ -0,0 +1,11 @@
|
||||
package lab2;
|
||||
|
||||
public class task4 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
char toto = (char)(24661);
|
||||
System.out.println(toto);
|
||||
System.out.println((int)(toto));
|
||||
}
|
||||
|
||||
}
|
10
src/lab2/task5.java
Normal file
10
src/lab2/task5.java
Normal file
@ -0,0 +1,10 @@
|
||||
package lab2;
|
||||
|
||||
public class task5 {
|
||||
|
||||
public static void main(String[] args) { // Début du programme, section principal
|
||||
String s = TextTools.readText(); // Lit un texte depuis le terminal et l'enregistre dans une variable
|
||||
System.out.println(s); // Affiche le texte sauvé
|
||||
}
|
||||
|
||||
}
|
14
src/lab2/task6.java
Normal file
14
src/lab2/task6.java
Normal file
@ -0,0 +1,14 @@
|
||||
package lab2;
|
||||
|
||||
public class task6 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String s = TextTools.readText();
|
||||
System.out.println(s);
|
||||
s = TextTools.capitalize(s);
|
||||
System.out.println(s);
|
||||
|
||||
}
|
||||
|
||||
}
|
23
src/lab2/task7.java
Normal file
23
src/lab2/task7.java
Normal file
@ -0,0 +1,23 @@
|
||||
package lab2;
|
||||
|
||||
public class task7 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String s = TextTools.readText();
|
||||
s = TextTools.toUpperCase(s);
|
||||
System.out.println(s);
|
||||
System.out.println(TextTools.invert(s));
|
||||
System.out.println("Hello World");
|
||||
s = TextTools.toLowerCase(s);
|
||||
System.out.println(s);
|
||||
s = TextTools.deleteConsonants(s);
|
||||
System.out.println(s);
|
||||
s = TextTools.readText();
|
||||
s = TextTools.encrypt(s);
|
||||
System.out.println(s);
|
||||
System.out.println(s=TextTools.decrypt(s));
|
||||
|
||||
}
|
||||
|
||||
}
|
16
src/lab2/task8.java
Normal file
16
src/lab2/task8.java
Normal file
@ -0,0 +1,16 @@
|
||||
package lab2;
|
||||
|
||||
public class task8 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String texte_en_string = TextTools.readText();
|
||||
texte_en_string = TextTools.capitalize(texte_en_string);
|
||||
texte_en_string = TextTools.invert(texte_en_string);
|
||||
texte_en_string = TextTools.capitalize(texte_en_string);
|
||||
texte_en_string = TextTools.invert(texte_en_string);
|
||||
System.out.println(texte_en_string);
|
||||
|
||||
}
|
||||
|
||||
}
|
BIN
src/lab3/03-expression-test-loop-fr.pdf
Normal file
BIN
src/lab3/03-expression-test-loop-fr.pdf
Normal file
Binary file not shown.
47
src/lab3/DrawArrow.java
Normal file
47
src/lab3/DrawArrow.java
Normal file
@ -0,0 +1,47 @@
|
||||
package lab3;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Class using FunGraphics class to draw an arrow.
|
||||
*/
|
||||
public class DrawArrow {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 640;
|
||||
final int HEIGHT = 480;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
|
||||
//Set the drawing color to black
|
||||
display.setColor(Color.black);
|
||||
|
||||
/*
|
||||
* Here, you have to modify the code to draw an arrow using setPixel()
|
||||
*/
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
display.setPixel(200+i, 200);;
|
||||
wait(10);
|
||||
}
|
||||
for (int i = 0; i < 20; i++) {
|
||||
display.setPixel(300-i, 200+i);
|
||||
wait(10);
|
||||
}
|
||||
for (int i = 0; i < 20; i++) {
|
||||
display.setPixel(300-i, 200-i);
|
||||
wait(10);
|
||||
}
|
||||
}
|
||||
}
|
74
src/lab3/Input.java
Normal file
74
src/lab3/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab3;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
78
src/lab3/SimpleCalculator.java
Normal file
78
src/lab3/SimpleCalculator.java
Normal file
@ -0,0 +1,78 @@
|
||||
package lab3;
|
||||
/**
|
||||
* This class offers a simple calculator which computes three standard
|
||||
* operations on two numbers entered with the console
|
||||
*
|
||||
* @author Pierre-Andre Mudry (pandre.mudry@hevs.ch)
|
||||
* @author Pierre Roduit (pierre.roduit@hevs.ch)
|
||||
* @version 2.1
|
||||
* @date October 11th 2017
|
||||
*
|
||||
*/
|
||||
public class SimpleCalculator {
|
||||
|
||||
/**
|
||||
* Starting point of the program
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int x = 0, y = 0;
|
||||
boolean loop = true;
|
||||
|
||||
// Integer used to choose the operator type
|
||||
String operatorType = "0";
|
||||
|
||||
while (loop) {
|
||||
// Display the kind of operations that we can handle
|
||||
System.out.println("Choose now the operator, by entering a number between 1 and 3:\n"
|
||||
+ "1 - Addition\n"
|
||||
+ "2 - Subtraction\n"
|
||||
+ "3 - Multiplication\n"
|
||||
+ "quit - Quitter\n");
|
||||
|
||||
// Read the operator from the console
|
||||
System.out.print("Enter your choice : ");
|
||||
operatorType = Input.readString();
|
||||
if (operatorType.equals("quit")) {
|
||||
System.out.println("finishing");
|
||||
break;
|
||||
} else {
|
||||
System.out.println("debug1");
|
||||
System.out.println(operatorType);
|
||||
}
|
||||
|
||||
// Display the message
|
||||
System.out.println("Take care to enter only integer numbers !");
|
||||
System.out.print("Enter first integer: ");
|
||||
|
||||
// Read the two numbers from the console
|
||||
x = Input.readInt();
|
||||
System.out.print("Enter the second integer: ");
|
||||
y = Input.readInt();
|
||||
|
||||
// Decision tree (The place where you will insert a switch operator)
|
||||
|
||||
switch (operatorType) {
|
||||
case "1":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the addition is: " + (x + y));
|
||||
break;
|
||||
|
||||
case "2":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the subtraction is: " + (x - y));
|
||||
break;
|
||||
|
||||
case "3":
|
||||
// Display a text and the result of the operation
|
||||
System.out.println("Result of the multiplication is: " + (x * y));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Display an error message
|
||||
System.out.println("You did not enter a correct number for the operation.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
src/lab3/task1.java
Normal file
14
src/lab3/task1.java
Normal file
@ -0,0 +1,14 @@
|
||||
package lab3;
|
||||
|
||||
public class task1 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = 2147480000;
|
||||
for (int i = 0; i < 10; x++) {
|
||||
System.out.println("Number: " + x);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
src/lab3/task4.java
Normal file
32
src/lab3/task4.java
Normal file
@ -0,0 +1,32 @@
|
||||
package lab3;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task4 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 640;
|
||||
final int HEIGHT = 480;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH; i++) {
|
||||
for (int j = 0; j < HEIGHT; j++) {
|
||||
display.setPixel(i, j, Color.BLUE);
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
src/lab3/task5.java
Normal file
31
src/lab3/task5.java
Normal file
@ -0,0 +1,31 @@
|
||||
package lab3;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task5 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int WIDTH = 256;
|
||||
final int HEIGHT = 256;
|
||||
|
||||
// Create and set the windows up
|
||||
FunGraphics display = new FunGraphics(WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH; i++) {
|
||||
for (int j = 0; j < HEIGHT; j++) {
|
||||
display.setPixel(i, j, new Color(i, 0, j));
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
src/lab3/task6.java
Normal file
33
src/lab3/task6.java
Normal file
@ -0,0 +1,33 @@
|
||||
package lab3;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class task6 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int width = 400;
|
||||
int height = 400;
|
||||
boolean condition = false;
|
||||
FunGraphics display = new FunGraphics(width, height);
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
condition = false;
|
||||
int dist_x = Math.abs(i-200);
|
||||
int dist_y = Math.abs(j-200);
|
||||
int distance = (int) Math.sqrt( Math.pow(dist_x, 2) + Math.pow(dist_y, 2));
|
||||
// pythagore pour distance
|
||||
if (distance < 100) {
|
||||
condition = true;
|
||||
}
|
||||
|
||||
if (condition) {
|
||||
display.setPixel(i, j, Color.BLUE);
|
||||
} else {
|
||||
display.setPixel(i, j, Color.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
34
src/lab3/task7.java
Normal file
34
src/lab3/task7.java
Normal file
@ -0,0 +1,34 @@
|
||||
package lab3;
|
||||
import hevs.graphics.FunGraphics;
|
||||
//import java.awt.Color;
|
||||
|
||||
public class task7 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
int width = 1000;
|
||||
int height = 1000;
|
||||
int delay = 1;
|
||||
int tps_total = 600000;
|
||||
FunGraphics display = new FunGraphics(width, height);
|
||||
|
||||
|
||||
for (double i = 0; i < (tps_total/delay); i+= 0.01) {
|
||||
display.setPixel( (int)(400*Math.sin(i) / (1+Math.cos(i)*Math.cos(i))+500) , (int)((400*Math.sin(i)*Math.cos(i)) / (1+Math.cos(i)*Math.cos(i))+500));
|
||||
wait(delay);
|
||||
//mieux par gestion du framreate (voir sur le site https://inf1.begincoding.net/la-librairie-fungraphics-2/)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
BIN
src/lab4/05-functions-fr.pdf
Normal file
BIN
src/lab4/05-functions-fr.pdf
Normal file
Binary file not shown.
155
src/lab4/DottedFlag.java
Normal file
155
src/lab4/DottedFlag.java
Normal file
@ -0,0 +1,155 @@
|
||||
package lab4;
|
||||
import hevs.graphics.FunGraphics;
|
||||
import hevs.utils.Input;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Class using {@link FunGraphics} class to draw a dotted Flag.
|
||||
*/
|
||||
public class DottedFlag {
|
||||
|
||||
// Constant parameters
|
||||
final static int GRAPHICS_WIDTH = 640;
|
||||
final static int GRAPHICS_HEIGHT = 480;
|
||||
final static int DOT_DISTANCE = 20;
|
||||
final static int DOT_RADIUS = 8;
|
||||
final static int STARTING_POSITION_X = 10;
|
||||
final static int STARTING_POSITION_Y = 10;
|
||||
|
||||
// Display surface to draw on
|
||||
public static FunGraphics display;
|
||||
|
||||
public static void drawDisc(int radius, int Cx, int Cy){
|
||||
display.setColor(Color.red);
|
||||
|
||||
// Draws a red disc
|
||||
for (int x = 0; x < GRAPHICS_WIDTH; x++){
|
||||
for (int y = 0; y < GRAPHICS_HEIGHT; y++){
|
||||
double distance = (Cx - x) * (Cx - x) + (Cy - y) * (Cy - y);
|
||||
|
||||
if (distance <= radius*radius){
|
||||
display.setPixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastDrawDisc(int radius, int Cx, int Cy){
|
||||
display.setColor(Color.red);
|
||||
|
||||
|
||||
// Draws a red disc
|
||||
for (int x = Cx-radius; x <= Cx+radius; x++){
|
||||
for (int y = Cy-radius; y <= Cy+radius; y++){
|
||||
double distance = (Cx - x) * (Cx - x) + (Cy - y) * (Cy - y);
|
||||
|
||||
if (distance <= radius*radius){
|
||||
display.setPixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fastDrawDisc(int radius, int Cx, int Cy, Color c){
|
||||
display.setColor(c);
|
||||
|
||||
|
||||
|
||||
// Draws a red disc
|
||||
for (int x = Cx-radius; x <= Cx+radius; x++){
|
||||
for (int y = Cy-radius; y <= Cy+radius; y++){
|
||||
double distance = (Cx - x) * (Cx - x) + (Cy - y) * (Cy - y);
|
||||
|
||||
if (distance <= radius*radius){
|
||||
display.setPixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.print("Please select \"fast\" or \"slow\" method: ");
|
||||
String s = Input.readString();
|
||||
|
||||
// Create and set the windows up
|
||||
display = new FunGraphics(GRAPHICS_WIDTH, GRAPHICS_HEIGHT);
|
||||
|
||||
// int Cx=GRAPHICS_WIDTH/2;
|
||||
// int Cy=GRAPHICS_HEIGHT/2;
|
||||
int radius=8;
|
||||
|
||||
display.setColor(Color.red);
|
||||
|
||||
long begin = System.currentTimeMillis();
|
||||
|
||||
if (s.equals("slow")) {
|
||||
|
||||
for (int y = 0; y < GRAPHICS_HEIGHT; y++) {
|
||||
for (int x = 0; x < GRAPHICS_WIDTH; x++) {
|
||||
if ( (x+10)%(+20)==0 && (x<(GRAPHICS_WIDTH-radius-10)) ) {
|
||||
if ( (y+30)%(+20)==0 && (y<(GRAPHICS_HEIGHT-radius-30)) ) {
|
||||
drawDisc(radius, x+10, y+30);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (s.equals("fast")) {
|
||||
|
||||
for (int y = 0; y < GRAPHICS_HEIGHT; y++) {
|
||||
for (int x = 0; x < GRAPHICS_WIDTH; x++) {
|
||||
if ( (x+10)%(+20)==0 && (x<(GRAPHICS_WIDTH-radius-10)) ) {
|
||||
if ( (y+30)%(+20)==0 && (y<(GRAPHICS_HEIGHT-radius-30)) ) {
|
||||
fastDrawDisc(radius, x+10, y+30);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println("please select \"fast\" or \"slow\" method");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
long result = System.currentTimeMillis()-begin;
|
||||
System.out.println("Drawing took " + result + " ms");
|
||||
|
||||
display.clear();
|
||||
|
||||
int ligne = 0;
|
||||
Color c;
|
||||
|
||||
for (int y = 0; y < GRAPHICS_HEIGHT; y++) {
|
||||
int colonne = 1;
|
||||
for (int x = 0; x < GRAPHICS_WIDTH; x++) {
|
||||
if ( (x+10)%(+20)==0 && (x<(GRAPHICS_WIDTH-radius-10)) ) {
|
||||
colonne ++;
|
||||
ligne++;
|
||||
if ( (y+30)%(+20)==0 && (y<(GRAPHICS_HEIGHT-radius-30)) ) {
|
||||
ligne++;
|
||||
|
||||
if (ligne%2 == 0) {
|
||||
if (colonne%2==0) {
|
||||
c = Color.blue;
|
||||
} else {
|
||||
c = Color.black;
|
||||
}
|
||||
} else {
|
||||
if (colonne%2==0) {
|
||||
c = Color.red;
|
||||
} else {
|
||||
c = Color.green;
|
||||
}
|
||||
}
|
||||
fastDrawDisc(radius, x+10, y+30, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
src/lab4/Input.java
Normal file
74
src/lab4/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab4;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
22
src/lab4/StringFunctions.java
Normal file
22
src/lab4/StringFunctions.java
Normal file
@ -0,0 +1,22 @@
|
||||
package lab4;
|
||||
public class StringFunctions {
|
||||
/**
|
||||
* @param s
|
||||
* @return The length (number of letters) of the String s
|
||||
*/
|
||||
public static int stringLength(String s){
|
||||
return s.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Example :
|
||||
* stringCharAt("hello", 0) returns 'h'
|
||||
* stringCharAt("hello", 1) returns 'e'
|
||||
* @param s
|
||||
* @param pos
|
||||
* @return The char at position pos in s
|
||||
*/
|
||||
public static char stringCharAt(String s, int pos){
|
||||
return s.charAt(pos);
|
||||
}
|
||||
}
|
37
src/lab4/task1.java
Normal file
37
src/lab4/task1.java
Normal file
@ -0,0 +1,37 @@
|
||||
package lab4;
|
||||
|
||||
public class task1 {
|
||||
|
||||
public static int NbrL(String s, char l) {
|
||||
|
||||
int total = 0;
|
||||
for (int i = 0; i < StringFunctions.stringLength(s); i++) {
|
||||
if (StringFunctions.stringCharAt(s, i)==l) {
|
||||
total += 1;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public static String inv(String s) {
|
||||
String result = "";
|
||||
int longeur = StringFunctions.stringLength(s);
|
||||
for (int i = 1; i <= longeur; i++) {
|
||||
result += StringFunctions.stringCharAt(s, (longeur-i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = Input.readString();
|
||||
/*for (int i = 0; i < 26; i++) {
|
||||
System.out.println("Nombre de " + (char)('a'+i) + ": " + NbrL(s, (char)(i+'a')));
|
||||
}*/
|
||||
for (char i = 'a'; i < 'z'; i++){ // boucle de a a Z
|
||||
System.out.println("Nombre de " + i + ": " + NbrL(s, i));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
src/lab4/task2.java
Normal file
11
src/lab4/task2.java
Normal file
@ -0,0 +1,11 @@
|
||||
package lab4;
|
||||
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
char toto = 'a';
|
||||
//toto = toto +1;
|
||||
System.out.println(toto);
|
||||
toto += 1;
|
||||
System.out.println(toto);
|
||||
}
|
||||
}
|
36
src/lab4/task3.java
Normal file
36
src/lab4/task3.java
Normal file
@ -0,0 +1,36 @@
|
||||
package lab4;
|
||||
|
||||
public class task3 {
|
||||
|
||||
public static double areaTriangle(int side, double radius) {
|
||||
double alpha = ((360/side/2)*Math.PI)/180;
|
||||
double sideS = sideS(alpha, radius);
|
||||
double heightH = heightH(alpha, radius);
|
||||
double area = (sideS*heightH)/2;
|
||||
return area;
|
||||
}
|
||||
|
||||
public static double sideS(double alpha, double radius) {
|
||||
return 2*radius*Math.sin(alpha);
|
||||
}
|
||||
|
||||
public static double heightH(double alpha, double radius) {
|
||||
return radius*Math.cos(alpha);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int side = 12;
|
||||
double radius = Math.sqrt(2)*5;
|
||||
/*
|
||||
System.out.println("How many side of your polygon ?");
|
||||
side = Input.readInt();
|
||||
|
||||
System.out.println("How big is your radius [cm] ?");
|
||||
radius = Input.readDouble();
|
||||
*/
|
||||
double area = side * areaTriangle(side, radius);
|
||||
System.out.println("Total area = " + area + " [cm2]");
|
||||
|
||||
}
|
||||
}
|
BIN
src/lab5/06_SecretNumber_FR.pdf
Normal file
BIN
src/lab5/06_SecretNumber_FR.pdf
Normal file
Binary file not shown.
68
src/lab5/Dialogs.java
Normal file
68
src/lab5/Dialogs.java
Normal file
@ -0,0 +1,68 @@
|
||||
package lab5;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
|
||||
/**
|
||||
* This class allows to display simple messages and have graphical interfaces to
|
||||
* enter words and characters.
|
||||
*
|
||||
* @version 2.0
|
||||
*
|
||||
*/
|
||||
public class Dialogs {
|
||||
/**
|
||||
* This function open a dialog box to enter a hidden String. The dialog box
|
||||
* asks for a String containing a minimum of one character.
|
||||
*
|
||||
* @param message
|
||||
* The message displayed to ask for the hidden String
|
||||
* @return The hidden String entered
|
||||
*/
|
||||
public static String getHiddenString(String message) {
|
||||
JPasswordField passwordField = new JPasswordField(10);
|
||||
JFrame frame = new JFrame(message);
|
||||
// prompt the user to enter their name
|
||||
JOptionPane.showMessageDialog(frame, passwordField, message, JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
String s = new String(passwordField.getPassword());
|
||||
if (s.length() > 0)
|
||||
return s;
|
||||
else
|
||||
return getHiddenString("Enter at least one character");
|
||||
}
|
||||
|
||||
/**
|
||||
* This function open a dialog box to enter a character. This function
|
||||
* accepts only one character.
|
||||
*
|
||||
* @param message
|
||||
* The message asking for the character.
|
||||
* @return The character entered.
|
||||
*/
|
||||
public static char getChar(String message) {
|
||||
JFrame frame = new JFrame("Input a character please");
|
||||
// prompt the user to enter their name
|
||||
String s = JOptionPane.showInputDialog(frame, message);
|
||||
|
||||
if(s == null){
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
if (s.length() == 1)
|
||||
return s.charAt(0);
|
||||
else
|
||||
return getChar("Just one character");
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a dialog box to display a message.
|
||||
*
|
||||
* @param message
|
||||
* The message to display.
|
||||
*/
|
||||
public static void displayMessage(String message) {
|
||||
JOptionPane.showMessageDialog(null, message, null, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
135
src/lab5/Input.java
Normal file
135
src/lab5/Input.java
Normal file
@ -0,0 +1,135 @@
|
||||
package lab5;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* * The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br>
|
||||
* <br>
|
||||
* - String <br>
|
||||
* - Integer (int) <br>
|
||||
* - Double (double) - Boolean (boolean) <br>
|
||||
* - Character (char) <br>
|
||||
* <br>
|
||||
* <br>
|
||||
*
|
||||
* @author Patrice Rudaz (patrice.rudaz@hevs.ch)
|
||||
* @author Cathy Berthouzoz (cathy.berthouzoz@hevs.ch)
|
||||
* @modified Pierre-Andr<64> Mudry
|
||||
* @version 3.0 - 6-10-2008
|
||||
* @see #readString()
|
||||
* @see #readLong()
|
||||
* @see #readLong()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input {
|
||||
/**
|
||||
* * Reads a valid char value from the console.
|
||||
*
|
||||
* @return The typed char
|
||||
* @see java.lang.Character
|
||||
*/
|
||||
public static char readChar() {
|
||||
boolean ok = false;
|
||||
int res = -1;
|
||||
while (!ok) {
|
||||
try {
|
||||
BufferedReader stdin = new BufferedReader(
|
||||
new InputStreamReader(System.in));
|
||||
res = stdin.read();
|
||||
ok = Character.isDefined(res);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("This is not a valid character. Try again");
|
||||
}
|
||||
}
|
||||
return (char) res;
|
||||
}
|
||||
|
||||
/**
|
||||
* * Reads a String from the console.
|
||||
*
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString() {
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(
|
||||
System.in));
|
||||
try {
|
||||
return stdin.readLine();
|
||||
} catch (Exception ex) {
|
||||
return "There is a problem. Try again.";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * Reads a valid integer value from the console.
|
||||
*
|
||||
* @return The typed value
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt() {
|
||||
boolean ok = false;
|
||||
int res = -1;
|
||||
while (!ok) {
|
||||
try {
|
||||
BufferedReader stdin = new BufferedReader(
|
||||
new InputStreamReader(System.in));
|
||||
String s = stdin.readLine();
|
||||
if (s.startsWith("0x") || s.startsWith("0X")) {
|
||||
res = Integer.parseInt(s.substring(2), 16);
|
||||
} else {
|
||||
res = Integer.parseInt(s, 10);
|
||||
}
|
||||
ok = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("This is not a valid number. Try again");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* * Reads a valid double value from the console.
|
||||
*
|
||||
* @return The typed double value
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble() {
|
||||
boolean ok = false;
|
||||
double res = -1;
|
||||
while (!ok) {
|
||||
try {
|
||||
BufferedReader stdin = new BufferedReader(
|
||||
new InputStreamReader(System.in));
|
||||
res = Double.parseDouble(stdin.readLine());
|
||||
ok = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("This is not a valid number. Try again");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* * Reads a valid boolean value from the console.
|
||||
*
|
||||
* @return the value true if the typed value is true, false otherwise.
|
||||
* @see java.lang.Boolean
|
||||
*/
|
||||
public static boolean readBoolean() {
|
||||
boolean ok = false;
|
||||
boolean res = false;
|
||||
while (!ok) {
|
||||
try {
|
||||
BufferedReader stdin = new BufferedReader(
|
||||
new InputStreamReader(System.in));
|
||||
res = Boolean.parseBoolean(stdin.readLine());
|
||||
ok = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("This is not a valid boolean. Try again");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
142
src/lab5/secretNumber.java
Normal file
142
src/lab5/secretNumber.java
Normal file
@ -0,0 +1,142 @@
|
||||
package lab5;
|
||||
|
||||
import hevs.utils.Input;
|
||||
|
||||
public class secretNumber {
|
||||
|
||||
public static void displayMenu() {
|
||||
String s = "";
|
||||
s += "************************************* \n";
|
||||
s += "* Secret Number - Can you find it ? * \n";
|
||||
s += "************************************* \n";
|
||||
s += "Choose difficulty level : \n";
|
||||
s += " (1) Rookie level (1 to 10) \n";
|
||||
s += " (2) Easy level (1 to 100) \n";
|
||||
s += " (3) Normal level (1 to 1000) \n";
|
||||
s += " (4) Nightmare level (1 to 100000) \n";
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
public static int askUser(String s) {
|
||||
System.out.print(">> " + s);
|
||||
return Input.readInt();
|
||||
}
|
||||
|
||||
public static int generateSecretNumber(int max) {
|
||||
double random = Math.random();
|
||||
random *= max;
|
||||
return (int) Math.floor(random)+1;
|
||||
}
|
||||
|
||||
public static int compare(int secret, int guess) {
|
||||
if (secret == guess) {
|
||||
return 0;
|
||||
} else if (secret < guess){
|
||||
return -1;
|
||||
} else { // secret > guess
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean end(int nbrTry, int minTries) {
|
||||
if (nbrTry<minTries){
|
||||
System.out.println("\n!!!! Congratulations !!!!");
|
||||
}
|
||||
System.out.println("You succed with " + nbrTry + " tries.");
|
||||
System.out.println("");
|
||||
char foo;
|
||||
do {
|
||||
System.out.print("Do you want to play another party ? (y/n)");
|
||||
foo = Input.readChar();
|
||||
if(foo == 'n'){
|
||||
System.exit(1);
|
||||
}
|
||||
} while (foo != 'y');
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int dichotomie(int secretNumber, int upper) {
|
||||
int nbrMin = 0;
|
||||
int min = 0;
|
||||
int max = upper;
|
||||
int test = 0;
|
||||
do {
|
||||
nbrMin++;
|
||||
test = (max-min)/2+min;
|
||||
if (test>secretNumber){
|
||||
max = test;
|
||||
}
|
||||
if (test<secretNumber){
|
||||
min = test;
|
||||
}
|
||||
if ( (max-min)==1 ){
|
||||
test = max;
|
||||
}
|
||||
} while (test != secretNumber);
|
||||
return nbrMin;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
while (true) {
|
||||
|
||||
int nbrTry = 0;
|
||||
displayMenu();
|
||||
int choice;
|
||||
do {
|
||||
choice = askUser("What is your choice ? ");
|
||||
} while (choice<1 || choice>4);
|
||||
|
||||
int upperLimit = 0;
|
||||
switch (choice) {
|
||||
case 1:
|
||||
upperLimit = 10;
|
||||
break;
|
||||
case 2:
|
||||
upperLimit = 100;
|
||||
break;
|
||||
case 3:
|
||||
upperLimit = 1000;
|
||||
break;
|
||||
case 4:
|
||||
upperLimit = 100000;
|
||||
break;
|
||||
default:
|
||||
System.exit(-1);
|
||||
break;
|
||||
}
|
||||
int secretNumber = generateSecretNumber(upperLimit);
|
||||
//System.out.println("Secret number is " + secretNumber);
|
||||
int minTries = dichotomie(secretNumber, upperLimit);
|
||||
System.out.println("You can find with " + minTries);
|
||||
boolean search = true;
|
||||
|
||||
while (search) {
|
||||
choice = askUser("Enter your guess : ");
|
||||
if (choice == 0){
|
||||
System.out.println("The good answer was "+secretNumber);
|
||||
System.exit(1);
|
||||
}
|
||||
nbrTry++;
|
||||
switch (compare(secretNumber, choice)) {
|
||||
case 0:
|
||||
search = false;
|
||||
if(end(nbrTry, minTries)){
|
||||
System.out.println("");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
System.out.println("The number is bigger than " + choice);
|
||||
break;
|
||||
case -1:
|
||||
System.out.println("The number is smaller than " + choice);
|
||||
break;
|
||||
|
||||
default:
|
||||
System.exit(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/lab6/07-HangMan_FR.pdf
Normal file
BIN
src/lab6/07-HangMan_FR.pdf
Normal file
Binary file not shown.
68
src/lab6/Dialogs.java
Normal file
68
src/lab6/Dialogs.java
Normal file
@ -0,0 +1,68 @@
|
||||
package lab6;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
|
||||
/**
|
||||
* This class allows to display simple messages and have graphical interfaces to
|
||||
* enter words and characters.
|
||||
*
|
||||
* @version 2.0
|
||||
*
|
||||
*/
|
||||
public class Dialogs {
|
||||
/**
|
||||
* This function open a dialog box to enter a hidden String. The dialog box
|
||||
* asks for a String containing a minimum of one character.
|
||||
*
|
||||
* @param message
|
||||
* The message displayed to ask for the hidden String
|
||||
* @return The hidden String entered
|
||||
*/
|
||||
public static String getHiddenString(String message) {
|
||||
JPasswordField passwordField = new JPasswordField(10);
|
||||
JFrame frame = new JFrame(message);
|
||||
// prompt the user to enter their name
|
||||
JOptionPane.showMessageDialog(frame, passwordField, message, JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
String s = new String(passwordField.getPassword());
|
||||
if (s.length() > 0)
|
||||
return s;
|
||||
else
|
||||
return getHiddenString("Enter at least one character");
|
||||
}
|
||||
|
||||
/**
|
||||
* This function open a dialog box to enter a character. This function
|
||||
* accepts only one character.
|
||||
*
|
||||
* @param message
|
||||
* The message asking for the character.
|
||||
* @return The character entered.
|
||||
*/
|
||||
public static char getChar(String message) {
|
||||
JFrame frame = new JFrame("Input a character please");
|
||||
// prompt the user to enter their name
|
||||
String s = JOptionPane.showInputDialog(frame, message);
|
||||
|
||||
if(s == null){
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
if (s.length() == 1)
|
||||
return s.charAt(0);
|
||||
else
|
||||
return getChar("Just one character");
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a dialog box to display a message.
|
||||
*
|
||||
* @param message
|
||||
* The message to display.
|
||||
*/
|
||||
public static void displayMessage(String message) {
|
||||
JOptionPane.showMessageDialog(null, message, null, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
97
src/lab6/HangMan.java
Normal file
97
src/lab6/HangMan.java
Normal file
@ -0,0 +1,97 @@
|
||||
package lab6;
|
||||
import hevs.graphics.FunGraphics;
|
||||
|
||||
public class HangMan {
|
||||
final int MAX_STEPS = 8;
|
||||
final int scale = 2;
|
||||
int current_step = 0;
|
||||
WordManager word = new WordManager();
|
||||
FunGraphics man = new FunGraphics(300*scale, 300*scale, 0, 0, "Hangman", true);
|
||||
|
||||
boolean play(){
|
||||
boolean party = true;
|
||||
//System.out.print("Please enter a new letter: ");
|
||||
//char c = Input.readChar();
|
||||
char c = Dialogs.getChar("Please enter a new letter");
|
||||
boolean validLetter = word.checkLetter(c);
|
||||
if(!validLetter){
|
||||
current_step++;
|
||||
}
|
||||
updateGraphicsView();
|
||||
if (current_step >= MAX_STEPS) {
|
||||
party = false;
|
||||
//System.out.println("Sorry, you have lost ;( ");
|
||||
Dialogs.displayMessage("Sorry, you have lost ;(");
|
||||
|
||||
}
|
||||
|
||||
return party;
|
||||
}
|
||||
|
||||
void updateGraphicsView(){
|
||||
man.clear();
|
||||
man.drawString(20*scale, 60*scale, "Word : " + word.userWord);
|
||||
for (int i = 1; i <= current_step; i++) {
|
||||
switch (i) { // dessin du pendu
|
||||
case 1:
|
||||
man.drawLine(110*scale, 210*scale, 120*scale, 190*scale);
|
||||
man.drawLine(130*scale, 210*scale, 120*scale, 190*scale);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
man.drawLine(120*scale, 190*scale, 120*scale, 100*scale);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
man.drawLine(120*scale, 100*scale, 180*scale, 100*scale);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
man.drawLine(180*scale, 100*scale, 180*scale, 110*scale);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
man.drawCircle(170*scale, 110*scale, 20*scale);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
man.drawLine(180*scale, 130*scale, 180*scale, 170*scale);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
man.drawLine(180*scale, 170*scale, 170*scale, 190*scale);
|
||||
man.drawLine(180*scale, 170*scale, 190*scale, 190*scale);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
man.drawLine(170*scale, 150*scale, 190*scale, 150*scale);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HangMan hang = new HangMan();
|
||||
while (true) {
|
||||
hang.word.askSecretWord();
|
||||
hang.current_step = 0;
|
||||
hang.updateGraphicsView();
|
||||
while (hang.play() && !hang.word.isWordComplete()) {
|
||||
System.out.println(hang.word.userWord);
|
||||
}
|
||||
//System.out.print ("Do you want play another party ? (y/n) ");
|
||||
//char answer = Input.readChar();
|
||||
char answer = Dialogs.getChar("Do you want play another party ? (y/n) ");
|
||||
if (answer != 'y' && answer != 'Y') {
|
||||
//System.out.println("Ok, see you later.");
|
||||
Dialogs.displayMessage("Ok, see you later.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
74
src/lab6/Input.java
Normal file
74
src/lab6/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab6;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
30
src/lab6/Person.java
Normal file
30
src/lab6/Person.java
Normal file
@ -0,0 +1,30 @@
|
||||
package lab6;
|
||||
|
||||
public class Person {
|
||||
String surname = "";
|
||||
String name = "";
|
||||
int age;
|
||||
double height;
|
||||
|
||||
Person(String name, String surname, int age, double d){
|
||||
this.surname = surname;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.height = d;
|
||||
}
|
||||
|
||||
void birthday(){
|
||||
age++;
|
||||
}
|
||||
|
||||
void display(){
|
||||
System.out.print(name);
|
||||
System.out.print(" ");
|
||||
System.out.print(surname);
|
||||
System.out.print(", ");
|
||||
System.out.print(age);
|
||||
System.out.print(", ");
|
||||
System.out.print(height);
|
||||
System.out.println("m.");
|
||||
}
|
||||
}
|
23
src/lab6/Task1.java
Normal file
23
src/lab6/Task1.java
Normal file
@ -0,0 +1,23 @@
|
||||
package lab6;
|
||||
|
||||
public class Task1 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Person toto = new Person("Jean", "Neymar", 22, 1.7);
|
||||
Person jack = new Person("Jadk", "Ady", 22, 1.7);
|
||||
|
||||
|
||||
|
||||
toto.display();
|
||||
jack.display();
|
||||
|
||||
toto.birthday();
|
||||
jack.birthday();
|
||||
jack.birthday();
|
||||
|
||||
toto.display();
|
||||
jack.display();
|
||||
|
||||
|
||||
}
|
||||
}
|
49
src/lab6/WordManager.java
Normal file
49
src/lab6/WordManager.java
Normal file
@ -0,0 +1,49 @@
|
||||
package lab6;
|
||||
import java.text.Normalizer;
|
||||
|
||||
public class WordManager {
|
||||
private String secretWord = "";
|
||||
public String userWord = "";
|
||||
|
||||
void askSecretWord(){
|
||||
//System.out.print("Enter your secret word: ");
|
||||
//String s = Input.readString();
|
||||
secretWord = Dialogs.getHiddenString("Enter your secret word: ");
|
||||
secretWord = stripAccents(secretWord);
|
||||
secretWord = secretWord.toLowerCase();
|
||||
userWord = "";
|
||||
|
||||
for (int i = 0; i < secretWord.length(); i++) {
|
||||
userWord += '*';
|
||||
}
|
||||
}
|
||||
|
||||
boolean checkLetter(char c){
|
||||
boolean letterPresent = false;
|
||||
for (int i = 0; i < secretWord.length(); i++) {
|
||||
if(c == secretWord.charAt(i)){
|
||||
letterPresent = true;
|
||||
userWord = userWord.substring(0, i) + c + userWord.substring(i+1);
|
||||
}
|
||||
}
|
||||
return letterPresent;
|
||||
}
|
||||
|
||||
boolean isWordComplete(){
|
||||
boolean complete = false;
|
||||
if (secretWord.equals(userWord)) {
|
||||
complete = true;
|
||||
//System.out.println("Victory !!");
|
||||
Dialogs.displayMessage("Victory !!");
|
||||
}
|
||||
return complete;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String stripAccents(String s){
|
||||
s = Normalizer.normalize(s, Normalizer.Form.NFD);
|
||||
s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
||||
return s;
|
||||
}
|
||||
}
|
600
src/lab6/french_common_words.csv
Normal file
600
src/lab6/french_common_words.csv
Normal file
@ -0,0 +1,600 @@
|
||||
bleu;Adjectif
|
||||
super;Adjectif
|
||||
autre;Adjectif
|
||||
bizarre;Adjectif
|
||||
difficile;Adjectif
|
||||
drôle;Adjectif
|
||||
étrange;Adjectif
|
||||
facile;Adjectif
|
||||
grave;Adjectif
|
||||
impossible;Adjectif
|
||||
jeune;Adjectif
|
||||
juste;Adjectif
|
||||
libre;Adjectif
|
||||
malade;Adjectif
|
||||
même;Adjectif
|
||||
pauvre;Adjectif
|
||||
possible;Adjectif
|
||||
propre;Adjectif
|
||||
rouge;Adjectif
|
||||
sale;Adjectif
|
||||
simple;Adjectif
|
||||
tranquille;Adjectif
|
||||
triste;Adjectif
|
||||
vide;Adjectif
|
||||
bonne;Adjectif féminin
|
||||
toute;Adjectif féminin
|
||||
doux;Adjectif masculin
|
||||
faux;Adjectif masculin
|
||||
français;Adjectif masculin
|
||||
gros;Adjectif masculin
|
||||
heureux;Adjectif masculin
|
||||
mauvais;Adjectif masculin
|
||||
sérieux;Adjectif masculin
|
||||
vieux;Adjectif masculin
|
||||
vrai;Adjectif masculin
|
||||
ancien;Adjectif masculin
|
||||
beau;Adjectif masculin
|
||||
blanc;Adjectif masculin
|
||||
certain;Adjectif masculin
|
||||
chaud;Adjectif masculin
|
||||
cher;Adjectif masculin
|
||||
clair;Adjectif masculin
|
||||
content;Adjectif masculin
|
||||
dernier;Adjectif masculin
|
||||
désolé;Adjectif masculin
|
||||
différent;Adjectif masculin
|
||||
droit;Adjectif masculin
|
||||
entier;Adjectif masculin
|
||||
fort;Adjectif masculin
|
||||
froid;Adjectif masculin
|
||||
gentil;Adjectif masculin
|
||||
grand;Adjectif masculin
|
||||
haut;Adjectif masculin
|
||||
humain;Adjectif masculin
|
||||
important;Adjectif masculin
|
||||
joli;Adjectif masculin
|
||||
léger;Adjectif masculin
|
||||
long;Adjectif masculin
|
||||
meilleur;Adjectif masculin
|
||||
mort;Adjectif masculin
|
||||
noir;Adjectif masculin
|
||||
nouveau;Adjectif masculin
|
||||
pareil;Adjectif masculin
|
||||
petit;Adjectif masculin
|
||||
plein;Adjectif masculin
|
||||
premier;Adjectif masculin
|
||||
prêt;Adjectif masculin
|
||||
prochain;Adjectif masculin
|
||||
quoi;Adjectif masculin
|
||||
seul;Adjectif masculin
|
||||
tout;Adjectif masculin
|
||||
vert;Adjectif masculin
|
||||
vivant;Adjectif masculin
|
||||
aide;Nom commun
|
||||
chef;Nom commun
|
||||
enfant;Nom commun
|
||||
garde;Nom commun
|
||||
gauche;Nom commun
|
||||
geste;Nom commun
|
||||
gosse;Nom commun
|
||||
livre;Nom commun
|
||||
merci;Nom commun
|
||||
mort;Nom commun
|
||||
ombre;Nom commun
|
||||
part;Nom commun
|
||||
poche;Nom commun
|
||||
professeur;Nom commun
|
||||
tour;Nom commun
|
||||
fois;Nom commun féminin
|
||||
madame;Nom commun féminin
|
||||
paix;Nom commun féminin
|
||||
voix;Nom commun féminin
|
||||
affaire;Nom commun féminin
|
||||
année;Nom commun féminin
|
||||
arme;Nom commun féminin
|
||||
armée;Nom commun féminin
|
||||
attention;Nom commun féminin
|
||||
balle;Nom commun féminin
|
||||
boîte;Nom commun féminin
|
||||
bouche;Nom commun féminin
|
||||
carte;Nom commun féminin
|
||||
cause;Nom commun féminin
|
||||
chambre;Nom commun féminin
|
||||
chance;Nom commun féminin
|
||||
chose;Nom commun féminin
|
||||
classe;Nom commun féminin
|
||||
confiance;Nom commun féminin
|
||||
couleur;Nom commun féminin
|
||||
cour;Nom commun féminin
|
||||
cuisine;Nom commun féminin
|
||||
dame;Nom commun féminin
|
||||
dent;Nom commun féminin
|
||||
droite;Nom commun féminin
|
||||
école;Nom commun féminin
|
||||
église;Nom commun féminin
|
||||
envie;Nom commun féminin
|
||||
épaule;Nom commun féminin
|
||||
époque;Nom commun féminin
|
||||
équipe;Nom commun féminin
|
||||
erreur;Nom commun féminin
|
||||
espèce;Nom commun féminin
|
||||
face;Nom commun féminin
|
||||
façon;Nom commun féminin
|
||||
faim;Nom commun féminin
|
||||
famille;Nom commun féminin
|
||||
faute;Nom commun féminin
|
||||
femme;Nom commun féminin
|
||||
fenêtre;Nom commun féminin
|
||||
fête;Nom commun féminin
|
||||
fille;Nom commun féminin
|
||||
fleur;Nom commun féminin
|
||||
force;Nom commun féminin
|
||||
forme;Nom commun féminin
|
||||
guerre;Nom commun féminin
|
||||
gueule;Nom commun féminin
|
||||
habitude;Nom commun féminin
|
||||
heure;Nom commun féminin
|
||||
histoire;Nom commun féminin
|
||||
idée;Nom commun féminin
|
||||
image;Nom commun féminin
|
||||
impression;Nom commun féminin
|
||||
jambe;Nom commun féminin
|
||||
joie;Nom commun féminin
|
||||
journée;Nom commun féminin
|
||||
langue;Nom commun féminin
|
||||
lettre;Nom commun féminin
|
||||
lèvre;Nom commun féminin
|
||||
ligne;Nom commun féminin
|
||||
lumière;Nom commun féminin
|
||||
main;Nom commun féminin
|
||||
maison;Nom commun féminin
|
||||
maman;Nom commun féminin
|
||||
manière;Nom commun féminin
|
||||
marche;Nom commun féminin
|
||||
merde;Nom commun féminin
|
||||
mère;Nom commun féminin
|
||||
minute;Nom commun féminin
|
||||
musique;Nom commun féminin
|
||||
nuit;Nom commun féminin
|
||||
odeur;Nom commun féminin
|
||||
oreille;Nom commun féminin
|
||||
parole;Nom commun féminin
|
||||
partie;Nom commun féminin
|
||||
peau;Nom commun féminin
|
||||
peine;Nom commun féminin
|
||||
pensée;Nom commun féminin
|
||||
personne;Nom commun féminin
|
||||
peur;Nom commun féminin
|
||||
photo;Nom commun féminin
|
||||
pièce;Nom commun féminin
|
||||
pierre;Nom commun féminin
|
||||
place;Nom commun féminin
|
||||
police;Nom commun féminin
|
||||
porte;Nom commun féminin
|
||||
présence;Nom commun féminin
|
||||
prison;Nom commun féminin
|
||||
putain;Nom commun féminin
|
||||
question;Nom commun féminin
|
||||
raison;Nom commun féminin
|
||||
réponse;Nom commun féminin
|
||||
robe;Nom commun féminin
|
||||
route;Nom commun féminin
|
||||
salle;Nom commun féminin
|
||||
scène;Nom commun féminin
|
||||
seconde;Nom commun féminin
|
||||
sécurité;Nom commun féminin
|
||||
semaine;Nom commun féminin
|
||||
situation;Nom commun féminin
|
||||
soeur;Nom commun féminin
|
||||
soirée;Nom commun féminin
|
||||
sorte;Nom commun féminin
|
||||
suite;Nom commun féminin
|
||||
table;Nom commun féminin
|
||||
terre;Nom commun féminin
|
||||
tête;Nom commun féminin
|
||||
vérité;Nom commun féminin
|
||||
ville;Nom commun féminin
|
||||
voiture;Nom commun féminin
|
||||
avis;Nom commun masculin
|
||||
bois;Nom commun masculin
|
||||
bras;Nom commun masculin
|
||||
choix;Nom commun masculin
|
||||
corps;Nom commun masculin
|
||||
cours;Nom commun masculin
|
||||
gars;Nom commun masculin
|
||||
mois;Nom commun masculin
|
||||
pays;Nom commun masculin
|
||||
prix;Nom commun masculin
|
||||
propos;Nom commun masculin
|
||||
sens;Nom commun masculin
|
||||
temps;Nom commun masculin
|
||||
travers;Nom commun masculin
|
||||
vieux;Nom commun masculin
|
||||
accord;Nom commun masculin
|
||||
agent;Nom commun masculin
|
||||
amour;Nom commun masculin
|
||||
appel;Nom commun masculin
|
||||
arbre;Nom commun masculin
|
||||
argent;Nom commun masculin
|
||||
avenir;Nom commun masculin
|
||||
avion;Nom commun masculin
|
||||
bateau;Nom commun masculin
|
||||
bébé;Nom commun masculin
|
||||
besoin;Nom commun masculin
|
||||
bonheur;Nom commun masculin
|
||||
bonjour;Nom commun masculin
|
||||
bord;Nom commun masculin
|
||||
boulot;Nom commun masculin
|
||||
bout;Nom commun masculin
|
||||
bruit;Nom commun masculin
|
||||
bureau;Nom commun masculin
|
||||
café;Nom commun masculin
|
||||
camp;Nom commun masculin
|
||||
capitaine;Nom commun masculin
|
||||
chat;Nom commun masculin
|
||||
chemin;Nom commun masculin
|
||||
chéri;Nom commun masculin
|
||||
cheval;Nom commun masculin
|
||||
cheveu;Nom commun masculin
|
||||
chien;Nom commun masculin
|
||||
ciel;Nom commun masculin
|
||||
client;Nom commun masculin
|
||||
cœur;Nom commun masculin
|
||||
coin;Nom commun masculin
|
||||
colonel;Nom commun masculin
|
||||
compte;Nom commun masculin
|
||||
copain;Nom commun masculin
|
||||
côté;Nom commun masculin
|
||||
coup;Nom commun masculin
|
||||
courant;Nom commun masculin
|
||||
début;Nom commun masculin
|
||||
départ;Nom commun masculin
|
||||
dieu;Nom commun masculin
|
||||
docteur;Nom commun masculin
|
||||
doigt;Nom commun masculin
|
||||
dollar;Nom commun masculin
|
||||
doute;Nom commun masculin
|
||||
droit;Nom commun masculin
|
||||
effet;Nom commun masculin
|
||||
endroit;Nom commun masculin
|
||||
ennemi;Nom commun masculin
|
||||
escalier;Nom commun masculin
|
||||
esprit;Nom commun masculin
|
||||
état;Nom commun masculin
|
||||
être;Nom commun masculin
|
||||
exemple;Nom commun masculin
|
||||
fait;Nom commun masculin
|
||||
film;Nom commun masculin
|
||||
flic;Nom commun masculin
|
||||
fond;Nom commun masculin
|
||||
français;Nom commun masculin
|
||||
frère;Nom commun masculin
|
||||
front;Nom commun masculin
|
||||
garçon;Nom commun masculin
|
||||
général;Nom commun masculin
|
||||
genre;Nom commun masculin
|
||||
goût;Nom commun masculin
|
||||
gouvernement;Nom commun masculin
|
||||
grand;Nom commun masculin
|
||||
groupe;Nom commun masculin
|
||||
haut;Nom commun masculin
|
||||
homme;Nom commun masculin
|
||||
honneur;Nom commun masculin
|
||||
hôtel;Nom commun masculin
|
||||
instant;Nom commun masculin
|
||||
intérêt;Nom commun masculin
|
||||
intérieur;Nom commun masculin
|
||||
jardin;Nom commun masculin
|
||||
jour;Nom commun masculin
|
||||
journal;Nom commun masculin
|
||||
lieu;Nom commun masculin
|
||||
long;Nom commun masculin
|
||||
maître;Nom commun masculin
|
||||
mari;Nom commun masculin
|
||||
mariage;Nom commun masculin
|
||||
matin;Nom commun masculin
|
||||
médecin;Nom commun masculin
|
||||
mètre;Nom commun masculin
|
||||
milieu;Nom commun masculin
|
||||
million;Nom commun masculin
|
||||
moment;Nom commun masculin
|
||||
monde;Nom commun masculin
|
||||
monsieur;Nom commun masculin
|
||||
mouvement;Nom commun masculin
|
||||
moyen;Nom commun masculin
|
||||
noir;Nom commun masculin
|
||||
nouveau;Nom commun masculin
|
||||
numéro;Nom commun masculin
|
||||
oeil;Nom commun masculin
|
||||
oiseau;Nom commun masculin
|
||||
oncle;Nom commun masculin
|
||||
ordre;Nom commun masculin
|
||||
papa;Nom commun masculin
|
||||
papier;Nom commun masculin
|
||||
parent;Nom commun masculin
|
||||
passage;Nom commun masculin
|
||||
passé;Nom commun masculin
|
||||
patron;Nom commun masculin
|
||||
père;Nom commun masculin
|
||||
petit;Nom commun masculin
|
||||
peuple;Nom commun masculin
|
||||
pied;Nom commun masculin
|
||||
plaisir;Nom commun masculin
|
||||
plan;Nom commun masculin
|
||||
point;Nom commun masculin
|
||||
pouvoir;Nom commun masculin
|
||||
premier;Nom commun masculin
|
||||
présent;Nom commun masculin
|
||||
président;Nom commun masculin
|
||||
prince;Nom commun masculin
|
||||
problème;Nom commun masculin
|
||||
quartier;Nom commun masculin
|
||||
rapport;Nom commun masculin
|
||||
regard;Nom commun masculin
|
||||
reste;Nom commun masculin
|
||||
retard;Nom commun masculin
|
||||
retour;Nom commun masculin
|
||||
rêve;Nom commun masculin
|
||||
revoir;Nom commun masculin
|
||||
salut;Nom commun masculin
|
||||
sang;Nom commun masculin
|
||||
secret;Nom commun masculin
|
||||
seigneur;Nom commun masculin
|
||||
sentiment;Nom commun masculin
|
||||
service;Nom commun masculin
|
||||
seul;Nom commun masculin
|
||||
siècle;Nom commun masculin
|
||||
signe;Nom commun masculin
|
||||
silence;Nom commun masculin
|
||||
soir;Nom commun masculin
|
||||
soldat;Nom commun masculin
|
||||
soleil;Nom commun masculin
|
||||
sourire;Nom commun masculin
|
||||
souvenir;Nom commun masculin
|
||||
sujet;Nom commun masculin
|
||||
téléphone;Nom commun masculin
|
||||
tout;Nom commun masculin
|
||||
train;Nom commun masculin
|
||||
travail;Nom commun masculin
|
||||
trou;Nom commun masculin
|
||||
truc;Nom commun masculin
|
||||
type;Nom commun masculin
|
||||
vent;Nom commun masculin
|
||||
ventre;Nom commun masculin
|
||||
verre;Nom commun masculin
|
||||
village;Nom commun masculin
|
||||
visage;Nom commun masculin
|
||||
voyage;Nom commun masculin
|
||||
fils;Nom commun masculin pluriel
|
||||
gens;Nom commun pluriel
|
||||
abandonner;Verbe
|
||||
accepter;Verbe
|
||||
accompagner;Verbe
|
||||
acheter;Verbe
|
||||
adorer;Verbe
|
||||
agir;Verbe
|
||||
aider;Verbe
|
||||
aimer;Verbe
|
||||
ajouter;Verbe
|
||||
aller;Verbe
|
||||
amener;Verbe
|
||||
amuser;Verbe
|
||||
annoncer;Verbe
|
||||
apercevoir;Verbe
|
||||
apparaître;Verbe
|
||||
appeler;Verbe
|
||||
apporter;Verbe
|
||||
apprendre;Verbe
|
||||
approcher;Verbe
|
||||
arranger;Verbe
|
||||
arrêter;Verbe
|
||||
arriver;Verbe
|
||||
asseoir;Verbe
|
||||
assurer;Verbe
|
||||
attaquer;Verbe
|
||||
atteindre;Verbe
|
||||
attendre;Verbe
|
||||
avancer;Verbe
|
||||
avoir;Verbe
|
||||
baisser;Verbe
|
||||
battre;Verbe
|
||||
boire;Verbe
|
||||
bouger;Verbe
|
||||
brûler;Verbe
|
||||
cacher;Verbe
|
||||
calmer;Verbe
|
||||
casser;Verbe
|
||||
cesser;Verbe
|
||||
changer;Verbe
|
||||
chanter;Verbe
|
||||
charger;Verbe
|
||||
chercher;Verbe
|
||||
choisir;Verbe
|
||||
commencer;Verbe
|
||||
comprendre;Verbe
|
||||
compter;Verbe
|
||||
conduire;Verbe
|
||||
connaître;Verbe
|
||||
continuer;Verbe
|
||||
coucher;Verbe
|
||||
couper;Verbe
|
||||
courir;Verbe
|
||||
couvrir;Verbe
|
||||
craindre;Verbe
|
||||
crier;Verbe
|
||||
croire;Verbe
|
||||
danser;Verbe
|
||||
décider;Verbe
|
||||
découvrir;Verbe
|
||||
dégager;Verbe
|
||||
demander;Verbe
|
||||
descendre;Verbe
|
||||
désoler;Verbe
|
||||
détester;Verbe
|
||||
détruire;Verbe
|
||||
devenir;Verbe
|
||||
deviner;Verbe
|
||||
devoir;Verbe
|
||||
dire;Verbe
|
||||
disparaître;Verbe
|
||||
donner;Verbe
|
||||
dormir;Verbe
|
||||
échapper;Verbe
|
||||
écouter;Verbe
|
||||
écrire;Verbe
|
||||
éloigner;Verbe
|
||||
embrasser;Verbe
|
||||
emmener;Verbe
|
||||
empêcher;Verbe
|
||||
emporter;Verbe
|
||||
enlever;Verbe
|
||||
entendre;Verbe
|
||||
entrer;Verbe
|
||||
envoyer;Verbe
|
||||
espérer;Verbe
|
||||
essayer;Verbe
|
||||
être;Verbe
|
||||
éviter;Verbe
|
||||
excuser;Verbe
|
||||
exister;Verbe
|
||||
expliquer;Verbe
|
||||
faire;Verbe
|
||||
falloir;Verbe
|
||||
fermer;Verbe
|
||||
filer;Verbe
|
||||
finir;Verbe
|
||||
foutre;Verbe
|
||||
frapper;Verbe
|
||||
gagner;Verbe
|
||||
garder;Verbe
|
||||
glisser;Verbe
|
||||
habiter;Verbe
|
||||
ignorer;Verbe
|
||||
imaginer;Verbe
|
||||
importer;Verbe
|
||||
inquiéter;Verbe
|
||||
installer;Verbe
|
||||
intéresser;Verbe
|
||||
inviter;Verbe
|
||||
jeter;Verbe
|
||||
jouer;Verbe
|
||||
jurer;Verbe
|
||||
lâcher;Verbe
|
||||
laisser;Verbe
|
||||
lancer;Verbe
|
||||
lever;Verbe
|
||||
lire;Verbe
|
||||
maintenir;Verbe
|
||||
manger;Verbe
|
||||
manquer;Verbe
|
||||
marcher;Verbe
|
||||
marier;Verbe
|
||||
mener;Verbe
|
||||
mentir;Verbe
|
||||
mettre;Verbe
|
||||
monter;Verbe
|
||||
montrer;Verbe
|
||||
mourir;Verbe
|
||||
naître;Verbe
|
||||
obliger;Verbe
|
||||
occuper;Verbe
|
||||
offrir;Verbe
|
||||
oser;Verbe
|
||||
oublier;Verbe
|
||||
ouvrir;Verbe
|
||||
paraître;Verbe
|
||||
parler;Verbe
|
||||
partir;Verbe
|
||||
passer;Verbe
|
||||
payer;Verbe
|
||||
penser;Verbe
|
||||
perdre;Verbe
|
||||
permettre;Verbe
|
||||
plaire;Verbe
|
||||
pleurer;Verbe
|
||||
porter;Verbe
|
||||
poser;Verbe
|
||||
pousser;Verbe
|
||||
pouvoir;Verbe
|
||||
préférer;Verbe
|
||||
prendre;Verbe
|
||||
préparer;Verbe
|
||||
présenter;Verbe
|
||||
prévenir;Verbe
|
||||
prier;Verbe
|
||||
promettre;Verbe
|
||||
proposer;Verbe
|
||||
protéger;Verbe
|
||||
quitter;Verbe
|
||||
raconter;Verbe
|
||||
ramener;Verbe
|
||||
rappeler;Verbe
|
||||
recevoir;Verbe
|
||||
reconnaître;Verbe
|
||||
réfléchir;Verbe
|
||||
refuser;Verbe
|
||||
regarder;Verbe
|
||||
rejoindre;Verbe
|
||||
remarquer;Verbe
|
||||
remettre;Verbe
|
||||
remonter;Verbe
|
||||
rencontrer;Verbe
|
||||
rendre;Verbe
|
||||
rentrer;Verbe
|
||||
répéter;Verbe
|
||||
répondre;Verbe
|
||||
reposer;Verbe
|
||||
reprendre;Verbe
|
||||
ressembler;Verbe
|
||||
rester;Verbe
|
||||
retenir;Verbe
|
||||
retirer;Verbe
|
||||
retourner;Verbe
|
||||
retrouver;Verbe
|
||||
réussir;Verbe
|
||||
réveiller;Verbe
|
||||
revenir;Verbe
|
||||
rêver;Verbe
|
||||
revoir;Verbe
|
||||
rire;Verbe
|
||||
risquer;Verbe
|
||||
rouler;Verbe
|
||||
sauter;Verbe
|
||||
sauver;Verbe
|
||||
savoir;Verbe
|
||||
sembler;Verbe
|
||||
sentir;Verbe
|
||||
séparer;Verbe
|
||||
serrer;Verbe
|
||||
servir;Verbe
|
||||
sortir;Verbe
|
||||
souffrir;Verbe
|
||||
sourire;Verbe
|
||||
souvenir;Verbe
|
||||
suffire;Verbe
|
||||
suivre;Verbe
|
||||
taire;Verbe
|
||||
tendre;Verbe
|
||||
tenir;Verbe
|
||||
tenter;Verbe
|
||||
terminer;Verbe
|
||||
tirer;Verbe
|
||||
tomber;Verbe
|
||||
toucher;Verbe
|
||||
tourner;Verbe
|
||||
traîner;Verbe
|
||||
traiter;Verbe
|
||||
travailler;Verbe
|
||||
traverser;Verbe
|
||||
tromper;Verbe
|
||||
trouver;Verbe
|
||||
tuer;Verbe
|
||||
utiliser;Verbe
|
||||
valoir;Verbe
|
||||
vendre;Verbe
|
||||
venir;Verbe
|
||||
vivre;Verbe
|
||||
voir;Verbe
|
||||
voler;Verbe
|
||||
vouloir;Verbe
|
|
208916
src/lab6/french_dictionary.txt
Normal file
208916
src/lab6/french_dictionary.txt
Normal file
File diff suppressed because it is too large
Load Diff
20
src/series/C05S03_loops/C05EX01a.java
Normal file
20
src/series/C05S03_loops/C05EX01a.java
Normal file
@ -0,0 +1,20 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C05EX01a {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int a, b, c;
|
||||
System.out.print("Veuillez entrer la première valeur: ");
|
||||
a = Input.readInt();
|
||||
System.out.print("Veuillez entrer la deuxième valeur: ");
|
||||
b = Input.readInt();
|
||||
System.out.print("Veuillez entrer la troisième valeur: ");
|
||||
c = Input.readInt();
|
||||
int max = a>b ? a:b;
|
||||
max = max>c ? max:c;
|
||||
System.out.println(max);
|
||||
|
||||
}
|
||||
}
|
14
src/series/C05S03_loops/C05EX01b.java
Normal file
14
src/series/C05S03_loops/C05EX01b.java
Normal file
@ -0,0 +1,14 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C05EX01b {
|
||||
public static void main(String[] args) {
|
||||
double a = Input.readDouble();
|
||||
if (a>=0) {
|
||||
System.out.println(Math.sqrt(a));
|
||||
} else {
|
||||
System.out.println("error");
|
||||
}
|
||||
}
|
||||
}
|
12
src/series/C05S03_loops/C05EX02.java
Normal file
12
src/series/C05S03_loops/C05EX02.java
Normal file
@ -0,0 +1,12 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX02 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
x = i+1;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
22
src/series/C05S03_loops/C05EX03.java
Normal file
22
src/series/C05S03_loops/C05EX03.java
Normal file
@ -0,0 +1,22 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX03 {
|
||||
public static void wait(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch(InterruptedException ex)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
int x = 2147483640;
|
||||
for (int i = 0; i < 10; x++) {
|
||||
System.out.println(x);
|
||||
wait(100);
|
||||
}
|
||||
}
|
||||
}
|
10
src/series/C05S03_loops/C05EX04a.java
Normal file
10
src/series/C05S03_loops/C05EX04a.java
Normal file
@ -0,0 +1,10 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX04a {
|
||||
public static void main(String[] args) {
|
||||
int foo =4;
|
||||
for (foo = 10; foo >=0; foo = foo - 3) {
|
||||
System.out.println(foo);
|
||||
}
|
||||
}
|
||||
}
|
11
src/series/C05S03_loops/C05EX04c.java
Normal file
11
src/series/C05S03_loops/C05EX04c.java
Normal file
@ -0,0 +1,11 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX04c {
|
||||
public static void main(String[] args) {
|
||||
int foo = 10;
|
||||
while (foo>=0) {
|
||||
System.out.println(foo);
|
||||
foo -= 3;
|
||||
}
|
||||
}
|
||||
}
|
11
src/series/C05S03_loops/C05EX04d.java
Normal file
11
src/series/C05S03_loops/C05EX04d.java
Normal file
@ -0,0 +1,11 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX04d {
|
||||
public static void main(String[] args) {
|
||||
int foo = 10;
|
||||
do {
|
||||
System.out.println(foo);
|
||||
foo-=3;
|
||||
} while (foo>=0);
|
||||
}
|
||||
}
|
11
src/series/C05S03_loops/C05EX07.java
Normal file
11
src/series/C05S03_loops/C05EX07.java
Normal file
@ -0,0 +1,11 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX07 {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
while (i<=20) {
|
||||
i++;
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
13
src/series/C05S03_loops/C05EX08a.java
Normal file
13
src/series/C05S03_loops/C05EX08a.java
Normal file
@ -0,0 +1,13 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08a {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i <= 1000; i++) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println(sum);
|
||||
|
||||
}
|
||||
}
|
13
src/series/C05S03_loops/C05EX08b.java
Normal file
13
src/series/C05S03_loops/C05EX08b.java
Normal file
@ -0,0 +1,13 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08b {
|
||||
public static void main(String[] args) {
|
||||
double sum = 0;
|
||||
int i;
|
||||
for (i = 0; i <= 1000; i++) {
|
||||
sum += i;
|
||||
}
|
||||
double average = sum/(i-1);
|
||||
System.out.println(average);
|
||||
}
|
||||
}
|
9
src/series/C05S03_loops/C05EX08c.java
Normal file
9
src/series/C05S03_loops/C05EX08c.java
Normal file
@ -0,0 +1,9 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08c {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 3; i < 100; i+=3) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
11
src/series/C05S03_loops/C05EX08d.java
Normal file
11
src/series/C05S03_loops/C05EX08d.java
Normal file
@ -0,0 +1,11 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08d {
|
||||
public static void main(String[] args) {
|
||||
for (int i = -5; i <= 5; i++) {
|
||||
if (i!=0) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
src/series/C05S03_loops/C05EX08e.java
Normal file
14
src/series/C05S03_loops/C05EX08e.java
Normal file
@ -0,0 +1,14 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08e {
|
||||
public static void main(String[] args) {
|
||||
String s = "";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int j = 0; j <= i; j++) {
|
||||
s += "*";
|
||||
}
|
||||
s += "-";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
11
src/series/C05S03_loops/C05EX08f.java
Normal file
11
src/series/C05S03_loops/C05EX08f.java
Normal file
@ -0,0 +1,11 @@
|
||||
package series.C05S03_loops;
|
||||
|
||||
public class C05EX08f {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 333; i <= 389; i++) {
|
||||
if (i%2==0) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/series/C05S03_loops/serie3.pdf
Normal file
BIN
src/series/C05S03_loops/serie3.pdf
Normal file
Binary file not shown.
40
src/series/C06S04_fonctions/C05EX01.java
Normal file
40
src/series/C06S04_fonctions/C05EX01.java
Normal file
@ -0,0 +1,40 @@
|
||||
package series.C06S04_fonctions;
|
||||
|
||||
import hevs.utils.Input;
|
||||
|
||||
public class C05EX01 {
|
||||
|
||||
// a
|
||||
public static float cube(float x) {
|
||||
return x*x*x;
|
||||
}
|
||||
|
||||
// b
|
||||
public static double puissance(int base, int exposant) {
|
||||
double resultat = 1.0;
|
||||
for (int i = 0; i < exposant; i++) {
|
||||
resultat *= base;
|
||||
}
|
||||
return resultat;
|
||||
}
|
||||
|
||||
// c
|
||||
public static void f1() {
|
||||
}
|
||||
|
||||
// d
|
||||
public static int NbrLettre(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// e
|
||||
public static boolean f2(int x1, int x2, String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int base = Input.readInt();
|
||||
int exposant = Input.readInt();
|
||||
System.out.println(puissance(base, exposant));
|
||||
}
|
||||
}
|
BIN
src/series/C06S04_fonctions/serie4.pdf
Normal file
BIN
src/series/C06S04_fonctions/serie4.pdf
Normal file
Binary file not shown.
16
src/series/theorie/C04EX0501.java
Normal file
16
src/series/theorie/C04EX0501.java
Normal file
@ -0,0 +1,16 @@
|
||||
package series.theorie;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C04EX0501 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a = Input.readInt();
|
||||
if (a>=0) {
|
||||
System.out.println(a);
|
||||
} else {
|
||||
System.out.println(-a);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/series/theorie/C04EX0502.java
Normal file
23
src/series/theorie/C04EX0502.java
Normal file
@ -0,0 +1,23 @@
|
||||
package series.theorie;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C04EX0502 {
|
||||
public static void main(String[] args) {
|
||||
while (true) {
|
||||
int a = Input.readInt();
|
||||
boolean b = false;
|
||||
|
||||
if (a%2 == 0) {
|
||||
b = true;
|
||||
}
|
||||
|
||||
if(b){
|
||||
System.out.println("La variable est paire");
|
||||
} else {
|
||||
System.out.println("La variable est impaire");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
20
src/series/theorie/C05EX01a.java
Normal file
20
src/series/theorie/C05EX01a.java
Normal file
@ -0,0 +1,20 @@
|
||||
package series.theorie;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C05EX01a {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int a, b, c;
|
||||
System.out.print("Veuillez entrer la première valeur: ");
|
||||
a = Input.readInt();
|
||||
System.out.print("Veuillez entrer la deuxième valeur: ");
|
||||
b = Input.readInt();
|
||||
System.out.print("Veuillez entrer la troisième valeur: ");
|
||||
c = Input.readInt();
|
||||
int max = a>b ? a:b;
|
||||
max = max>c ? max:c;
|
||||
System.out.println(max);
|
||||
|
||||
}
|
||||
}
|
14
src/series/theorie/C05EX01b.java
Normal file
14
src/series/theorie/C05EX01b.java
Normal file
@ -0,0 +1,14 @@
|
||||
package series.theorie;
|
||||
|
||||
import various_tests.Input;
|
||||
|
||||
public class C05EX01b {
|
||||
public static void main(String[] args) {
|
||||
double a = Input.readDouble();
|
||||
if (a>=0) {
|
||||
System.out.println(Math.sqrt(a));
|
||||
} else {
|
||||
System.out.println("error");
|
||||
}
|
||||
}
|
||||
}
|
12
src/series/theorie/C05EX02.java
Normal file
12
src/series/theorie/C05EX02.java
Normal file
@ -0,0 +1,12 @@
|
||||
package series.theorie;
|
||||
|
||||
public class C05EX02 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
x = i+1;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
19
src/series/theorie/C06EX06.java
Normal file
19
src/series/theorie/C06EX06.java
Normal file
@ -0,0 +1,19 @@
|
||||
package series.theorie;
|
||||
import hevs.utils.Input;
|
||||
|
||||
public class C06EX06 {
|
||||
|
||||
public static int somme(int x1, int x2, int x3){
|
||||
return x1+x2+x3;
|
||||
}
|
||||
|
||||
public static double petit(double x1, double x2) {
|
||||
return x1<x2?x1:x2;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("La somme est: " + somme(Input.readInt(), Input.readInt(), Input.readInt()));
|
||||
System.out.println("Le plus petit nombre est: " + petit(Input.readDouble(), Input.readDouble()));
|
||||
}
|
||||
|
||||
}
|
74
src/various_tests/Input.java
Normal file
74
src/various_tests/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package various_tests;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user