Java OOP Ispravka ispita: Bankovni račun i manipulacija datumima

Telechargé par Med Tadano
Faculté des sciences de Bizerte
Université de Carthage A.U : 2020/2021
__________________________________________________________________________________________
Section : SEIoT2 TP1
Enseignante : Anissa BEN TAHER
Matière : Programmation orientée objet
EXERCICE 1
CompteBancaire
-numeroCompte : int
-solde : float
+deposerArgent( float montant)
+retirerArgent(float montant)
-verifierSolde() :boolean
+afficherInformationCompte()
import java.util.Random;
public class CompteBancaire{
private int numeroCompte;
private float solde;
Correction TP3 JAVA
Faculté des sciences de Bizerte
Université de Carthage A.U : 2020/2021
__________________________________________________________________________________________
CompteBancaire( float solde)
{
this.numeroCompte=identifiantCompteBancaire();
this.solde=solde;
}
private int verifierSolde(float montant){
if (solde>montant) {
return 1;
}else{
return 0;
}
}
private int identifiantCompteBancaire()
{
int x=(int)(Math.random()*10000);
return x;
}
public void deposerArgent( float montant){
this.solde+=montant;
}
public void retirerArgent(float montant){
if(verifierSolde(montant)==1){
this.solde-=montant;
}
else {
Faculté des sciences de Bizerte
Université de Carthage A.U : 2020/2021
__________________________________________________________________________________________
System.out.println("Solde insuffisant !");
}
}
public int getNumeroCompte(){
return this.numeroCompte;
}
public float getSolde(){
return this.solde;
}
public void afficherInformationCompte() {
System.out.println("Le compte numéro: "+this.numeroCompte+ " possède le solde=
"+this.solde);
}
}
public class TestCompte{
public static void main (String[] args){
CompteBancaire cpt1= new CompteBancaire(2000);
CompteBancaire cpt2= new CompteBancaire(1000);
cpt1.afficherInformationCompte();
cpt2.afficherInformationCompte();
cpt1.deposerArgent(1000);
cpt2.retirerArgent(500);
Faculté des sciences de Bizerte
Université de Carthage A.U : 2020/2021
__________________________________________________________________________________________
cpt1.afficherInformationCompte();
cpt2.afficherInformationCompte();
}
}
EXERCICE 2
public class Date{
private int jour;
private int mois;
private int annee;
Date(int jour, int mois, int annee){
this.jour=jour;
this.mois=mois;
this.annee=annee;
}
public int getJour(){
return this.jour;
}
public int getMois(){
return this.mois;
}
public int getAnnee(){
Faculté des sciences de Bizerte
Université de Carthage A.U : 2020/2021
__________________________________________________________________________________________
return this.annee;
}
private boolean bissextille(int annee){
if ((annee % 400 == 0) || ((annee % 4 == 0) && (annee % 100 != 0))) {
return true;
} else {
return false;
}
}
public int nombreJours(Date d){
int mois=d.getMois();
boolean b=bissextille(d.getAnnee());
if(mois==1||mois==3||mois==5||mois==7||mois==8||mois==10||mois==12)
{
return 31;
} else if(mois==4||mois==6||mois==9||mois==11){
return 30;
}
else if(mois==2 && b==true){
return 29;
} else {
return 28;
}
}
1 / 9 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans l'interface ou les textes ? Ou savez-vous comment améliorer l'interface utilisateur de StudyLib ? N'hésitez pas à envoyer vos suggestions. C'est très important pour nous!