1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| public class Ville {
//Stocke le nom de notre ville
String nomVille;
//Stocke le nom du pays de notre ville
String nomPays;
//Stocke le nombre d'habitants de notre ville
int nbreHabitants;
//Constructeur par defaut
public Ville(){
System.out.println("Creation d'une ville !");
nomVille = "Inconnu";
nomPays = "Inconnu";
nbreHabitants = 0;
}
//Constructeur avec parametres
//J'ai ajoute un « p » en premiere lettre des parametres.
//Ce n'est pas une convention, mais ça peut être un bon moyen de les reperer.
public Ville(String pNom, int pNbre, String pPays)
{
System.out.println("Creation d'une ville avec des parametres !");
nomVille = pNom;
nomPays = pPays;
nbreHabitants = pNbre;
}
//************* ACCESSEURS *************
//Retourne le nom de la ville
public String getNom() {
return nomVille;
}
//Retourne le nom du pays
public String getNomPays()
{
return nomPays;
}
// Retourne le nombre d'habitants
public int getNombreHabitants()
{
return nbreHabitants;
}
//************* MUTATEURS *************
//Definit le nom de la ville
public void setNom(String pNom)
{
nomVille = pNom;
}
//Definit le nom du pays
public void setNomPays(String pPays)
{
nomPays = pPays;
}
//Definit le nombre d'habitants
public void setNombreHabitants(int nbre)
{
nbreHabitants = nbre;
}
public String laplus(Ville ville2){
if (this.nbreHabitants > ville2.getNombreHabitants())
return this.nomVille;
if (ville2.getNombreHabitants() > this.nbreHabitants)
return ville2.getNom();
return "null";
}
/*private void set Categorie(){
int categorie[] = {A, B, C, D}
int valeurs[] = {1000, 10000, 100000, 1000000}
int i = 0;
(while i <= 3)
if (this.nbreHabitants >
}*/
public String plusgrande(Ville ville2){
String str = new String();
if (this.nbreHabitants > ville2.getNombreHabitants())
str = this.nomVille+" est une ville plus peuplee que "+ville2.getNom();
if (ville2.getNombreHabitants() > this.nbreHabitants)
str = ville2.getNom()+" est une ville plus peuplee que "+this.nomVille;
return str;
}
} |
Partager