Devoir java:
Exercie1:
1et2:
public class book {
String titre;
String auteur;
int prix;
public String gettitre()
{
return titre;
}
public String getauteur()
{
return auteur;
}
public int getprix()
{
return prix;
}
public void settitre(String titre)
{
[Link]=titre;
}
public void setauteur(String auteur)
{
[Link]=auteur;
}
public void setprix(int prix)
{
[Link]=prix;
}
public static void main(String[] args) {
book b1=new book();
[Link]("les meserables");
[Link]("vector hergo");
[Link](80);
[Link]([Link]()+ "\n"+[Link]()+"\n"+ [Link]());
}}
3-
public class book {
String titre;
String auteur;
int prix;
public book(String titre,String auteur,int prix)
{
[Link]=titre;
[Link]=auteur;
[Link]=prix;
}
public static void main(String[] args) {
book b1=new book("LE PRINCE","NOUHAILA CHARAF",200);
book b2=new book("LA POMME","VECTOR HEGOF",100);
}}
4-
public class book {
String titre;
String auteur;
int prix;
public book(String titre,String auteur,int prix)
{
[Link]=titre;
[Link]=auteur;
[Link]=prix;
}
public void affiche(){
[Link](titre +"\n"+auteur +"\n" +prix);
}
public static void main(String[] args) {
book b1=new book("LE PRINCE","NOUHAILA CHARAF",200);
book b2=new book("LA POMME","VECTOR HEGOF",100);
[Link]();
[Link]();
}}
5-
public class test {
public static void main(String[] args) {
book[] livres = new book[3];
Scanner sc = null;
Object book;
for (int i = 0; i < [Link]; i++) {
sc = new Scanner([Link]);
[Link]("Donner le titre du livre n° " + (i + 1) + " :");
String titre = [Link]();
[Link]("Donner l'auteur du livre n° " + (i + 1) + " :");
String auteur = [Link]();
[Link]("Donner le prix du livre n° " + (i + 1) + " :");
int prix = [Link]();
book[i] = new book(titre, auteur, prix);}
[Link]();
for (book l :book)
[Link](l);
[Link]("Le nombre de livres est " + [Link]);
}}
Exercice2 :
1&2 :
package employe;
import [Link];
public class employe {
String matricule,nom,prenom;
long AnneNaiss,AnneEmbauche;
int salaire;
public String getmatricule()
{
return matricule;
}
public String getnom()
{
return nom;
}
public String getprenom()
{
return prenom;
}
public long getAnneNaiss()
{
return AnneNaiss;
}
public long getAnneEmbauche()
{
return AnneEmbauche;
}
public int getsalaire()
{
return salaire;
}
public void setmatricule(String matricule)
{
[Link]=matricule;
}
public void setnom(String nom)
{
[Link]=nom;
}
public void setprenom(String prenom)
{
[Link]=prenom;
}
public void setAnneNaiss(long AnneNaiss)
{
[Link]= AnneNaiss;
}
public void setAnneEmbauche(long AnneEmbauche)
{
[Link]=AnneEmbauche;
}
public void setsalaire(int salaire)
{
[Link]=salaire;
}
public static void main(String[] args) {
employe E1=new employe();
[Link]("dacias");
[Link]("chacha");
[Link]("ahmed");
[Link](1977);
[Link](2009);
[Link](20384);
System .[Link]("les information de l'employe est:\n");
System .[Link]([Link]()+"\n" +[Link]()+ "\n"+[Link]()+"\n"
+[Link]()+"\n"+[Link]()+"\n"+[Link]());}}
3&4&5&6&7:
package employe;
import [Link];
public class employe {
String matricule,nom,prenom;
long AnneNaiss,AnneEmbauche;
int age,Anciennete,salaire,nvsalaire;
public int getage()
{
return age;
}
public int getAnciennete() {
return Anciennete;
}
public void AugmentationDuSalaire(int Anciennete) {
if(Anciennete<5) {
nvsalaire = (int)(salaire +salaire*0.02);
[Link]("le nv salaire est: "+nvsalaire);
}
else if (Anciennete>5 && Anciennete<10) {
nvsalaire =(int)(salaire+salaire*0.05);
[Link]("le nv salaire est: "+nvsalaire);
}
else if(Anciennete>=10)
nvsalaire =(int)(salaire+salaire*0.1);
[Link]("le nv salaire est: " +nvsalaire);
}
public void afficheremploye()
{
[Link]("les information de l'employe est:\n");
[Link]("la matricule est: "+matricule );
[Link]("le nom et prenom et l'age est: "+nom +prenom +" "+age);
[Link]("l'anneNaissance est: "+AnneNaiss);
[Link]("l'annee d'embauche est: " +AnneEmbauche);
[Link]("le nombre d'anciennete est: "+ Anciennete);
[Link]("le salaire est: "+salaire);
public employe(String matricule,String nom,String prenom,long AnneNaiss,long
AnneEmbauche,int salaire,int Anciennete,int age)
{
[Link]=matricule;
[Link]=nom;
[Link]=prenom;
[Link]=AnneNaiss;
[Link]=AnneEmbauche;
[Link]=salaire;
[Link]=Anciennete;
[Link]=age;
public static void main(String[] args) {
employe E1=new
employe("dacias","chacha","ahmed",1977,2010,2000,10,30);
[Link]();
[Link]([Link]);}}
8-
Exercice3:
public class document {
String titre;
int numero;
static int numerosuivant=0;
public document(String titre) {
[Link] = numerosuivant;
numerosuivant++;
[Link] = titre;
}
public document(String titre, int numero) {
if (numero < numerosuivant) {
numero = numerosuivant;
}
[Link] = numero;
numerosuivant = numero + 1;
[Link] = titre;
}
public int getNumero(){
return numero;
}
public String getTitre(){
return titre;
}
public String toString() {
return ("numero: "+numero+" titre: "+titre);
}
public static void main(String[] args) {
document d1 =new document("abdjhbjhd",1);
document d2 =new document("abdjhbjhd",2);
document d3 =new document("abdjhbjhd",3);
document d4 =new document("abdjhbjhd",4);
document d5 =new document("abdjhbjhd",5);
[Link]([Link]() +"\n"+[Link]() +"\n"+ [Link]());
Exercice 4 :
//Fichier [Link]
import [Link] ;
public class Figure {
private static Vector instances = new Vector();
private int abscisse;
private int ordonnee;
private int couleur;
public Figure( int abscisse , int ordonnee , int couleur ) {
[Link] = abscisse;
[Link] = ordonnee;
[Link] = couleur;
[Link](this);
}
public static Vector getInstances() { return instances ; }
public String toString(){
return (abscisse+" "+ordonnee+" "+couleur);
}
}
public class Carre extends Figure {
private int cote ;
public Carre(int abscisse, int ordonnee, int couleur, int cote) {
super(abscisse,ordonnee,couleur);
[Link] = cote;
}
public static Vector getInstances() {
int nCarre = 0;
Vector instancesCarre = new Vector();
Vector instances = [Link]();
Enumeration e = [Link]();
Figure uneFigure;
while([Link]()) {
uneFigure = (Figure)[Link]();
if (uneFigure instanceof Carre)
[Link](uneFigure);
}
return instancesCarre;
}
public String toString(){
return ([Link]()+" "+cote);
}
}
//Fichier [Link]
import [Link] ;
import [Link] ;
public class Test {
public static void main(String[] argv) {
Figure f1 = new Figure(1,1,1);
Figure f2 = new Figure(2,2,2);
Carre c3 = new Carre(3,3,3,3);
Figure f4 = new Figure(4,4,4);
Carre c5 = new Carre(5,5,5,5);
[Link]("Liste des figures") ;
Enumeration e = [Link]().elements() ;
while([Link]()){
[Link]([Link]()) ;
}
[Link]("Liste des carres") ;
e = [Link]().elements() ;
while([Link]()){
[Link]([Link]()) ;
}
}
}