Académique Documents
Professionnel Documents
Culture Documents
TP2
Realiser par :omar bannour L2 TIC_TD1_TP1
Le code Main:
Exercice 1:
Le code:
package Ex1;
import java.util.Scanner;
public class TraitmementChaine {
String ch;
public TraitmementChaine(String ch) {
this.ch = ch;
}
public String getCh() {
return ch;
}
void LireChaine() {
Scanner input = new Scanner(System.in);
System.out.println("donner une chaine: ");
ch = input.nextLine();
}
public int compterNbreCarateres() {
return ch.length();
}
Resultat:
public int compterLettreMajuscule() {
int compteur = 0;
for (int i = 0; i < ch.length(); i++) {
char c= ch.charAt(i);
if (Character.isUpperCase(c)) {
compteur++;
}
}
return compteur;
}
public void verifierMot(String Mot){
int position = ch.indexOf(Mot);
if (position == -1){
System.out.println( "le mot n'existe pas");
}
else
System.out.println("le mot existe");
}
public void Nbroccurence(char caratere){
int compteur = 0;
for (int i = 0; i<ch.length();i++ ){
if (ch.charAt(i)==caratere){
compteur ++;
System.out.println( "le nombre d occurence est:" + compteur);
}
}
}
}
Exercice3:
Le code :
package Ex2;
public class Personne {
String nom; Main code:
int age;
char sexe;
public Personne(String nom , int
age , char sexe) {
this.nom = nom;
this.age = age;
this.sexe = sexe;
}
public String getNom() {
return nom;
}
public void setNom(String nom)
{
this.nom = nom;
} Resulat:
}
public void souhaiterAnniversaire(){
age =age+1;
System.out.println("happy birthady tu est maintenat :" + age);
}
public void saluer(){
if (sexe=='m') {
System.out.println("bonjour monseiur");
}
else
System.out.println("bonjour madame");
}
}
Exercice 4:
Le code:
package EX4;
public class Etudiant {
String nom;
Double moyenne;
String matierePrefree;
public Etudiant(String nom ,Double moyenne,String matierePrefree){
this.nom=nom; Le code Main:
this.moyenne=moyenne;
this.matierePrefree=matierePrefree;
}
public String getNom(){
return nom;
}
public void setNom(String nom){
this.nom=nom;
}
public Double getMoyenne() {
return moyenne;
}
public void setMoyenne(Double moyenne) {
this.moyenne = moyenne;
}
public String getMatierePrefree() { Resultat:
return matierePrefree;
}
public void setMatierePrefree(String matierePrefree)
{
this.matierePrefree = matierePrefree;
}
public void mention(){
if (moyenne>= 16){
System.out.println("mention trés bien");}
else if (moyenne<16 && moyenne >=14) {
System.out.println("mention bien");}
else if ( moyenne<14 && moyenne>=12) {
System.out.println("mention assez bien");}
else if ( moyenne<12 && moyenne>=10 ){
System.out.println("mention passable");}
else
System.out.println("insuffisante");}
public void afficheDetaills(){
System.out.println("le nom de l'etudiant est :" + nom);
System.out.println("le moyenne de l'etudiant est :" + moyenne);
System.out.println("le matiere prefere de l'etudiant est :" + matierePrefree);
mention();
}
public void changerMatierePreferee(String matierePrefree2){
matierePrefree = matierePrefree2;
System.out.println("votre nouvelle matiere preferee est:" +matierePrefree2);
}
public void ajouterNote(double note){
moyenne =(moyenne +note)/2;
System.out.println("le noveau moyenne est:" +moyenne);}
}
Exercice 5:
Le code:
package EX5;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;
}
Le code Main
Exercice 6:
Le code:
package EX6;
import java.util.Arrays;
}
else return produits;