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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
| /**
* Annuaire.java
* Base de données de personnes.
* Base est une classe dérivant de la classe Vector.
* Vecteur d'objets : conversion de type objet.
*/
import java.util.*; // pour la classe Vector.
class Personne {
// Retourne si le nom+prenom (n,p) est égal а celui de l'objet courant.
public boolean equals(String n, String p) {
/////////////////
// A compléter //
/////////////////
}
public void affiche() {
/////////////////
// A compléter //
/////////////////
}
}
// Classe Base dérivant de Vector
class Base ????????? {
public void ajouter(String nom, String prenom, int a, String adr) {
/////////////////
// A compléter //
/////////////////
// Afficher message si personne dejа présente.
}
public void retirer(String nom, String prenom) {
/////////////////
// A compléter //
/////////////////
// Afficher message si personne inconnue.
}
// Affiche les infos sur la personne passée en paramètre.
public void afficher(String nom, String prenom) {
/////////////////
// A compléter //
/////////////////
// Afficher message si personne inconnue.
}
// Retourne l'indice de la personne.
?????? int recherche(String nom, String prenom) {
/////////////////
// A compléter //
/////////////////
}
}
public class Annuaire {
public static void main(String[ ] args) {
/////////////////
// A compléter //
/////////////////
// Créer 1 base.
// Tester l'ajout, le retrait et l'affichage.
}
}
*******************************************************
public class Fiche implements Serializable{
private String nom;
private String prenom;
private String tel;
private String adresse;
/* Construit une nouvelle fiche sans paramêtre. */
public Fiche() {
nom = " ";
prenom = " ";
adresse = " ";
tel = " ";
}
// Construit une nouvelle fiche avec tous les paramêtres.
public Fiche(String n, String p, String t, String a) {
this.nom = n;
this.prenom = p;
this.tel = t;
this.adresse = a;
}
//****les accesseurs*****
/** Donner de Nom.
@return nom.
*/
public String getNom() {
return nom;
}
/** Donner de Prenom.
@return prenom.
*/
public String getPrenom() {
return prenom;
}
/** Donner numero de tel.
@return tel.
*/
public String getTel() {
return tel;
}
/** Donner d'adresse.
@return adresse.
*/
public String getAdresse() {
return adresse;
}
/** Modifier de Nom.
@param str nom.
*/
public void setNom(String str) {
nom = str;
}
/** Modifier de Prenom.
@param str prenom.
*/
public void setPrenom(String str) {
prenom = str;
}
/** Modifier de telephone.
@param str tel.
*/
public void setTel(String str) {
tel = str;
}
/** Modifier l'adresse.
@param str adresse.
*/
public void setAdresse(String str) {
adresse = str;
}
/** Retourne une chaîne représentant l'objet.
@return Chaîne représentant l'objet.
*/
public String toString() {
String outNom = "";
String outPrenom = "";
if (this.nom != null && this.nom.length() > 0){
outNom = this.nom + " ";
}
if (this.prenom != null){
outPrenom = this.prenom;
}
return outNom.toUpperCase() + outPrenom;
}
//sauver les informations des personne
public void enregistrer(Writer s) {
PrintWriter str = new PrintWriter(s);
str.print(nom);
str.print(':');
str.print(prenom);
str.print(':');
str.print(adresse);
str.print(':');
str.println(tel);
str.flush();
}
}
*********************************************************
public class Personne extends Fiche {
public Personne() {
}
// Retourne si le nom+prenom (n,p) est égal \u0430 celui de l'objet courant.
public boolean equals(Object o){
if (!(o instanceof Fiche))
return false;
Fiche fiche = (Fiche) o;
if ( this.getNom() == null ){
if (fiche.getNom()!= null) return false;
}
else if (! this.getNom().equals(fiche.getNom()))
return false;
if ( this.getPrenom()== null ){
if (fiche.getPrenom() != null) return false;
}
else if (! this.getPrenom().equals(fiche.getPrenom())) return false;
return true;
}
public void affiche() {
Fiche fiche= new Fiche();
fiche.getNom();
fiche.getPrenom();
System.out.println("entrez votre nom"+ equals(fiche));
System.out.println("entrez votre prenom" + equals(fiche));
}
public static void main(String[] args) {
Personne personne = new Personne();
personne.affiche();
}
}
****************************************
*********************************************
public class Base extends Vector {
public Base() {
}
public void ajouter(String nom, String prenom, String tel, String adr) {
Vector vect = new Vector();
if (nom == null || prenom == null || nom.equals("")) {
System.out.println("nom existe déja");
}
Fiche fiche = new Fiche(nom, prenom, tel, adr);
vect.add(fiche);
}
public void retirer(String nom, String prenom) {
Vector vect = new Vector();
if (nom != this.toString() && prenom != this.toString())
System.out.println("nom inconnu");
else
for (int i = 1; i <= vect.size(); i++)
{
removeElementAt(i);
}
}
// Affiche les infos sur la personne passée en paramètre.
public void afficher(String nom, String prenom) {
Vector vect = new Vector();
if (nom != null || prenom != null) {
for (int i = 1; i <= vect.size(); i++)
vect.get(i);
}
}
// Retourne l'indice de la personne.
public int recherche(String nom, String prenom) {
Vector vect = new Vector();
int n=1;
if (n >= 0 && n < vect.size()) {
String S = (String) vect.elementAt(n);
int pos = S.indexOf('=');
S = S.substring(pos + 1, S.length());
}return n;
}
}
***************************************** |
Partager