Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sdz1 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Ville v = new Ville();
- Ville v1 = new Ville("Marsehhille", 123456, "France");
- Ville v2 = new Ville("Rio", 4576, "Brésil");
- System.out.println("\n\n"+v1.descrisToi());
- System.out.println(v.descrisToi());
- System.out.println(v2.descrisToi()+"\n\n");
- System.out.println(v1.comparer(v2));
- System.out.println("===============================================================");
- System.out.println("\n v = "+v.getNom()+"ville de "+v.getNombreHabittants()+"Nombre d'habittants"+v.getNomPays());
- System.out.println("\n v1 = "+v1.getNom()+"ville de "+v1.getNombreHabittants()+"Nombre d'habittants"+v1.getNomPays());
- System.out.println("\n v1 = "+v2.getNom()+"ville de "+v2.getNombreHabittants()+"Nombre d'habittants"+v2.getNomPays());
- //Faire interchanger les deux ville v1 et v2
- Ville temp= new Ville();
- temp = v1;
- v1 = v2;
- v2 = temp;
- System.out.println("\n v1 = "+v1.getNom()+"ville de "+v1.getNombreHabittants()+"Nombre d'habittants"+v1.getNomPays());
- System.out.println("\n v1 = "+v2.getNom()+"ville de "+v2.getNombreHabittants()+"Nombre d'habittants"+v2.getNomPays());
- /*
- * Interchanre les noms par le biais des mutteurs
- * */
- v1.setNom("Hong Kong");
- v2.setNom("Djibouti");
- System.out.println("\n v1 = "+v1.getNom()+"ville de "+v1.getNombreHabittants()+"Nombre d'habittants"+v1.getNomPays());
- System.out.println("\n v1 = "+v2.getNom()+"ville de "+v2.getNombreHabittants()+"Nombre d'habittants"+v2.getNomPays());
- System.out.print("Vérification si l'héritage foncionne..."+v1.descrisToi()+v1.getMonument()+"=====");
- }
- }
- // Class Ville
- /*
- *
- * \t : tabulation
- \r : retour chariot
- \n : nouvelle ligne
- *
- */
- public class Ville {
- protected String nomVille;
- protected String nomPays;
- protected int nombHabitants;
- protected char categorie;
- //Constructeur
- public Ville() {
- System.out.println("Création d'une ville ! ");
- nomVille = "Inconnnu";
- nomPays = "Inconnu";
- nombHabitants = 0;
- this.setCategorie();
- }
- //******* Les accesseurs Gets *********//
- public String getNom() {
- return nomVille;
- }
- public String getNomPays() {
- return nomPays;
- }
- public int getNombreHabittants() {
- return nombHabitants;
- }
- //****** MUTATEURS sets *******//
- //Définir le nom de la ville
- public void setNom(String pNom) {
- nomVille = pNom;
- }
- //Définir le pays
- public void setNomPays(String pPays) {
- nomPays = pPays;
- }
- //Définir le nombre d'habittants
- public void setNombrebHabittants(int nbre) {
- nombHabitants = nbre;
- this.setCategorie();
- }
- public Ville(String pNom, int pNbr, String pPays) {
- System.out.println("Création d'une ville avec des paramètres");
- nomVille = pNom;
- nomPays = pPays;
- nombHabitants = pNbr;
- this.setCategorie();
- }
- //Définir la catégorie de la ville
- private void setCategorie() {
- int bornesSuperieures[] = {0, 1000, 10000, 100000, 500000, 1000000, 5000000, 10000000};
- char categorie[] = {'?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
- int i = 0;
- while (i < bornesSuperieures.length && this.nombHabitants > bornesSuperieures[i])
- i++;
- this.categorie = categorie[i];
- }
- //Retourne la description de la ville
- public String descrisToi() {
- return"\t"+this.nomVille+" est une ville de "+this.nomPays+" elle comporte"+this.nombHabitants+" d'habitants, elle est donc de la catégorie : "+this.categorie;
- }
- //Retourne une chaine de caractère selon le résultat de la comparaison
- public String comparer(Ville v1) {
- String str = new String();
- if (v1.getNombreHabittants()> this.nombHabitants)
- str = v1.getNom()+"est une ville plus peuplée que "+this.nomVille;
- else
- str = this.nomVille+"est une ville plus peuplée que"+v1.getNom();
- return str;
- }
- }
- //Capitale
- public class Capitale extends Ville {
- private String monument;
- //Constructeur par défaut
- public Capitale(){
- //Ce mot clé appelle le constructeur de la classe mère
- super();
- monument = "aucun";
- }
- //Constructeur d'initialisation de capitale
- public Capitale(String nom, int hab, String pays, String monument){
- super(nom, hab, pays);
- this.monument = monument;
- }
- /**
- * Description d'une capitale
- * @return String retourne la description de l'objet
- */
- public String decrisToi(){
- String str = super.descrisToi() + "\n \t ==>>" + this.monument + "en est un monument ***********lljljmkjkh";
- System.out.println("Invocation de super.descrsiToi");
- return str;
- }
- /**
- * @return le nom du monument
- */
- public String getMonument() {
- return monument;
- }
- //Définit le nom du monument
- public void setMonument(String monument) {
- this.monument = monument;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement