You are on page 1of 9

public class Employe {

private String nom;


public Employe(String nom) {
super();
this.nom = nom;
}
public Employe() {
// TODO Auto-generated constructor stub
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
// on va ajouter la methode getSalaire ici parce que on aura besoin de cette methode
pour l'hritage
public double getSalaire(){
return -1;
}
@Override
public String toString() {
return nom+" gagne "+getSalaire()+" F";
}
}
public class EmployeHoraire extends Employe{
private double tarifHor;
private final static int nbrHeurNr=39;
private int pourcentage;
private int nbrHeurTr;
public EmployeHoraire(String nom, double tarifHor, int pourcentage,
int nbrHeurTr) {
super(nom);
this.tarifHor = tarifHor;
this.pourcentage = pourcentage;
this.nbrHeurTr = nbrHeurTr;
}
public EmployeHoraire (String pNom){
super(pNom);
}

public void setInfosSalaire(double tarif, int pourctge, int nbrH){


tarifHor=tarif;
pourcentage=pourctge;
nbrHeurTr=nbrH;
}
// la methode getSalaire : il ya deux cas soit l'employ travall plus que 39 heures
soit il a travaill 39
public double getSalaire(){

if (nbrHeurTr > nbrHeurNr) {


double f=tarifHor*nbrHeurNr;
double d=tarifHor*(nbrHeurTr-nbrHeurNr)*pourcentage/100;
double r=tarifHor*(nbrHeurTr-nbrHeurNr);
return f+r+d;
}
else {
return tarifHor * nbrHeurTr;
}
}
public double getTarifHor() {
return tarifHor;
}
public void setTarifHor(double tarifHor) {
this.tarifHor = tarifHor;
}
public int getPourcentage() {
return pourcentage;
}
public void setPourcentage(int pourcentage) {
this.pourcentage = pourcentage;
}
public int getNbrHeurTr() {
return nbrHeurTr;
}
public void setNbrHeurTr(int nbrHeurTr) {
this.nbrHeurTr = nbrHeurTr;
}
public static int getNbrheurnr() {
return nbrHeurNr;
}
}
public class Commercial extends Employe {
private double sommefixe;

private static final int pourcentage = 1;


private double CA;
public Commercial(String nom, double sommefixe, double cA) {
super(nom);
this.sommefixe = sommefixe;
CA = cA;
}
public void setInfosSalaire(double somme, double pCA) {
sommefixe = somme;
CA = pCA;
}
// la methode getSalaire:
public double getSalaire() {
}

return sommefixe + (CA * pourcentage) / 100;

public double getSommefixe() {


return sommefixe;
}
public void setSommefixe(double sommefixe) {
this.sommefixe = sommefixe;
}
public static int getPourcentage() {
return pourcentage;
}
public double getCA() {
return CA;
}
public void setCA(double cA) {
CA = cA;
}
public Commercial(String nom) {
super(nom);
}
}
public class Paie {
public static void main(String[] args) {
Commercial c1=new Commercial("karimi", 1000, 50000);

Commercial c2=new Commercial("achatbi", 2000, 50000);


Commercial c3=new Commercial("achat", 3000, 50000);
Employe [] emps=new Employe[5];
emps[0]=c1;
emps[1]=c2;
emps[2]=c3;
EmployeHoraire e1=new EmployeHoraire("habri");
e1.setInfosSalaire(200, 30 ,45);
emps[3]=e1;
EmployeHoraire e2=new EmployeHoraire("abcd", 100, 40, 41);
emps[4]=e2;
for(int i=0; i<emps.length;i++){
}

System.out.println(emps[i].toString());

}
}
public class Point3D {
private double x;
private double y;
private double z;

public Point3D() {
// TODO Auto-generated constructor stub
}
public Point3D(double x, double y, double z) {
super();
this.x = x;
this.y = y;
this.z = z;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;

}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
public boolean equals(Point3D p) {
if(this.x==p.x && this.y==p.y && this.z==p.z)
return true;
return false;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
Point3D other = (Point3D) obj;
if(x==other.x && y==other.y && z==other.z)
return true;
return false;
}
@Override
public String toString() {
return "point : x="+x+" y="+y+" z="+z;
}
public Point3D deplacer(double dx, double dy, double dz){
Point3D p=new Point3D();
p.x=this.x+dx;
p.y=y+dy;
p.z=z+dz;
return p;

}
public static void main(String[] args) {
Point3D p1=new Point3D(1, 7, 3);
Point3D p2=new Point3D(1, 2, 3);
System.out.println(p1.equals(p2));
System.out.println(p1.toString());

import java.util.Scanner;

public class MathUtils {

static double moy ;


static float som =0;
static double tab1[]=null;

public static double moyenne (int n){


double tab[]=new double[n];
int j=0;
do {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez la valeur n" + (j+1) + " : ");
tab[j] = sc.nextDouble();
j++;
}while(j<tab.length);
for ( j=0 ; j<tab.length ; j++)
som +=tab[j] ;
moy=som/n;
tab1=tab;
return moy;
}

//------------------------------------------------------------------------------

public static double ecatType(int n,double [] tab ) {

double p=0;
double t=0;
for (int k=0 ; k<tab1.length ; k++)
t+=Math.pow(tab1[k], 2);
p=Math.sqrt(t/n-Math.pow(moy,2));
return p;
}

//-------------------------------------------------------------------------------

public static double fact(int n){


if (n==0) return 1;
else return n*fact(n-1);
}

public static double sinTaylor(double x,int k){


double sin=0;
for(int c=0;c<k;c++){
sin+=((Math.pow(-1,c)*Math.pow(x,2*c+1))/fact(2*c+1));
}
return sin;
}

//------------------------------------------------------------------------------

public static int sommeDiv(int n){

int i;
int somme=0;

for(i=1; i<=n; i++)


if(n%i==0) somme+=i;
return somme;
}

//------------------------------------------------------------------------------

public static boolean amis(int m, int n){


int q=sommeDiv(n);
int w=sommeDiv(m);
if(q==w) return true;
else return false;
}

//-------------------------- Programme de test des fonctions ---------------------

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("********* Moyenne et l'Ecart type *********");


System.out.print("Moyenne de combien de valeurs ?: ");
int x= sc.nextInt();
double w= MathUtils.moyenne(x);
System.out.println("Moyenne de ces valeurs est: "+w);
double z=MathUtils.ecatType(x,MathUtils.tab1);
System.out.println("L'cart type est : "+ z);

System.out.println("********* Fonction calcul la valeur de la fonction


sinus au point x avec la serie de taylor ********* ");
System.out.print("Donner la valeur de point x (en radians) : x= ");
double s= sc.nextDouble();
System.out.print("Combien de termes au devlopement en serie de
taylor ? : ");
int t= sc.nextInt();
double f=MathUtils.sinTaylor(s,t);
System.out.println("sin("+s+")= "+f);

System.out.println("********* calculant la somme des diviseurs de


l'entier n *********");
System.out.print("Entrer l'entier : n = ");
int d= sc.nextInt();
int d1= MathUtils.sommeDiv(d);
System.out.println("La somme des diviseurs de l'entier "+d+" est :
"+d1);

System.out.println("********* Savoir si deux entier m et n sont


amis********* ");
System.out.println("Entrer deux entier m et n :");
System.out.print("m= ");
int m1=sc.nextInt();
System.out.print("n= ");
int n1= sc.nextInt();
System.out.print(MathUtils.amis(m1,n1));
}
}

You might also like