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
| package com.eclipsetotale;
public class Ville {
public static int nbreInstance = 0;
protected static int nbreInstanceBis = 0;
protected String nomVille;
protected String nomPays;
protected int nbreHabitant;
protected char categorie;
public Ville()
{
//On incrémente nos variables à chaque appel au constructeur
nbreInstance++;
nbreInstanceBis++;
System.out.println("Création d'une ville");
nomVille = "Inconnu";
nomPays = "Inconnu";
nbreHabitant = 0;
}
//constructeur d'instenciation
public Ville(String pNom, int pNbre, String pPays)
{
System.out.println("Création d'une ville avec des paramètres");
nomVille = pNom;
nomPays = pPays;
nbreHabitant = pNbre;
}
public static int getNbreInstance()
{
return nbreInstance;
}
public static void setNbreInstance(int nbreInstance) {
Ville.nbreInstance = nbreInstance;
}
public static int getNbreInstanceBis() {
return nbreInstanceBis;
}
public static void setNbreInstanceBis(int nbreInstanceBis) {
Ville.nbreInstanceBis = nbreInstanceBis;
}
public String getNomVille() {
return nomVille;
}
public void setNomVille(String nomVille) {
this.nomVille = nomVille;
}
public String getNomPays() {
return nomPays;
}
public void setNomPays(String nomPays) {
this.nomPays = nomPays;
}
public int getNbreHabitant() {
return nbreHabitant;
}
public void setNbreHabitant(int nbreHabitant) {
this.nbreHabitant = nbreHabitant;
}
public char getCategorie() {
return categorie;
}
public void setCategorie(char categorie) {
this.categorie = categorie;
}
protected void setCategorie(){
int bornesSuperieures[] = {0,1000,10000,100000,500000,1000000,5000000,1000000000};
char categories[] = {'?','A','B','C','D','E','G','H'};
int i = 0;
while(i<bornesSuperieures.length && this.nbreHabitant >= bornesSuperieures[i])
i++;
this.categorie = categories[i];
}
class Capitale extends Ville
{
private String president;
public Capitale()
{
super();
president = "aucun";
}
public Capitale(String nom, int hab, String pays, String president)
{
super(nom,hab,pays);
this.president = president;
}
}
} |
Partager