Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Poo Contact Manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
william.viret
Poo Contact Manager
Commits
90b7c107
Commit
90b7c107
authored
Nov 4, 2022
by
william.viret
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
e2bc7bcd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ContactManager.java
+237
-0
237 additions, 0 deletions
ContactManager.java
with
237 additions
and
0 deletions
ContactManager.java
0 → 100644
+
237
−
0
View file @
90b7c107
import
java.util.ArrayList
;
import
javax.swing.event.SwingPropertyChangeSupport
;
import
java.util.Collections
;
import
java.util.Scanner
;
import
java.util.*
;
import
Projet.Contact
;
public
class
ContactManager
extends
Contact
{
public
ContactManager
(
String
nom
,
ArrayList
<
String
>
prenom
,
String
addresse
,
ArrayList
<
String
>
telephone
,
ArrayList
<
String
>
mail
,
ArrayList
<
String
>
social
,
String
job
)
{
super
(
nom
,
prenom
,
addresse
,
telephone
,
mail
,
social
,
job
);
//TODO Auto-generated constructor stub
}
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Contact
>
list
=
new
ArrayList
<
Contact
>();
// Contact("IV", "Henry", "brel", "Versaille", "118218", "Henry@IV.fr", "henry.social", "king");
while
(
true
){
ArrayList
<
String
>
prenomList
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
telephone
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
mail
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
social
=
new
ArrayList
<
String
>();
String
nom
,
addresse
,
job
;
System
.
out
.
println
(
"Bienvenue dans mon gestionnaire de contactes, que voulez vous faire ?"
);
System
.
out
.
println
(
"1 pour voir les contactes"
);
System
.
out
.
println
(
"2 pour modifier les contactes"
);
System
.
out
.
println
(
"3 pour ajouter un contacte"
);
System
.
out
.
println
(
"4 pour quitter"
);
Scanner
userMenuNavigation
=
new
Scanner
(
System
.
in
);
int
userChoice
=
userMenuNavigation
.
nextInt
();
Scanner
scanner
=
new
Scanner
(
System
.
in
);
if
(
userChoice
==
1
){
if
(
list
.
isEmpty
()){
System
.
out
.
println
(
"Il n'y a pas de contactes dans votre annuaire, ajouter en pour les afficher !"
);
continue
;
}
else
{
for
(
Contact
contact:
list
){
System
.
out
.
println
(
contact
);
}
}
}
else
if
(
userChoice
==
2
){
//Modifier les contactes
while
(
true
){
// on ne peut que modifier le prénom vu qu'on ne va pas le vendre a google
int
modificationAppliqué
=
0
;
System
.
out
.
println
(
"taper le nom du contact que vous voulez modifier :"
);
String
nomAModifier
=
scanner
.
nextLine
();
for
(
Contact
contactAModifer:
list
){
if
(
contactAModifer
.
getNom
().
equals
(
nomAModifier
)
){
System
.
out
.
println
(
"Rentrer le nouveau prénom du contact ( séparer par une , si il y en a plusieur"
);
nomAModifier
=
scanner
.
nextLine
();
ArrayList
<
String
>
myList
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
nomAModifier
.
split
(
","
)));
contactAModifer
.
setNouveauPrenom
(
myList
);
System
.
out
.
println
(
"Contact modifié avec succès"
);
modificationAppliqué
=
1
;
break
;
}
}
if
(
modificationAppliqué
==
1
)
break
;
System
.
out
.
println
(
"Le nom ne se trouve pas dans la liste"
);
}
}
else
if
(
userChoice
==
3
){
// N Prenom ajouté dans l'arrayList
while
(
true
)
{
System
.
out
.
println
(
"Entrer le prénom du contacte que vous voulez ajouter : "
);
String
nomScanner
=
scanner
.
nextLine
();
if
(
nomScanner
.
length
()>
0
){
prenomList
.
add
(
nomScanner
);
}
System
.
out
.
println
(
"Voulez vous ajouter un autre prénom ? (si non tapez juste \"non\")"
);
String
answer
=
scanner
.
next
();
if
(
answer
.
equals
(
"non"
)){
System
.
out
.
println
(
"Prénom ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
prenomList
);
break
;
}
else
{
if
(
answer
.
length
()>
0
){
prenomList
.
add
(
answer
);
}
}
}
// 1 x Nom ajouter dans un String
while
(
true
){
System
.
out
.
println
(
"Entrer le nom du contacte que vous voulez ajouter : "
);
String
nomScanner
=
scanner
.
nextLine
();
if
(
nomScanner
.
matches
(
"[a-zA-Z]+"
)
&&
nomScanner
.
length
()>
0
&&
nomScanner
.
length
()<
100
){
nom
=
nomScanner
;
System
.
out
.
println
(
"Nom ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
nom
);
break
;
}
else
{
System
.
out
.
println
(
"Nom non ajouter car il ne respecte pas les standards (a-z A-Z, min 1 caractère max 100 caractère merci de rentrer un nom valide"
);
}
}
// 1 x addresse ajouter dans un String
while
(
true
){
System
.
out
.
println
(
"Entrer l'addresse du contacte que vous voulez ajouter : "
);
addresse
=
scanner
.
nextLine
();
if
(
addresse
.
matches
(
"[a-zA-Z0-9 ]+"
)
&&
addresse
.
length
()>
0
&&
addresse
.
length
()<
255
){
System
.
out
.
println
(
"addresse ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
addresse
);
break
;
}
else
{
System
.
out
.
println
(
"Nom non ajouter car il ne respecte pas les standards (a-z A-Z, min 1 caractère max 255 caractère merci de rentrer un nom valide"
);
}
}
// N telephone ajouté dans l'arrayList
while
(
true
)
{
System
.
out
.
println
(
"Entrer le telephone du contacte que vous voulez ajouter : "
);
telephone
.
add
(
scanner
.
nextLine
());
System
.
out
.
println
(
"Voulez vous ajouter un autre telephone ? (si non tapez juste \"non\")"
);
String
answer
=
scanner
.
next
();
if
(
answer
.
equals
(
"non"
)){
System
.
out
.
println
(
"telephone ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
telephone
);
break
;
}
else
{
telephone
.
add
(
answer
);
}
}
// N mail ajouté dans l'arrayList
while
(
true
)
{
System
.
out
.
println
(
"Entrer le mail du contacte que vous voulez ajouter : "
);
String
mailScanner
=
scanner
.
next
();
if
(
mailScanner
.
length
()>
0
){
mail
.
add
(
mailScanner
);
System
.
out
.
println
(
"Voulez vous ajouter un autre mail ? (si non tapez juste \"non\")"
);
String
answer
=
scanner
.
next
();
if
(
answer
.
equals
(
"non"
)){
System
.
out
.
println
(
"mail ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
mail
);
break
;
}
else
{
mail
.
add
(
answer
);
}
}
}
// N Social ajouté dans l'arrayList
while
(
true
)
{
System
.
out
.
println
(
"Entrer l'addresse du réseau sociale du contacte que vous voulez ajouter : "
);
String
socialScanner
=
scanner
.
next
();
if
(
socialScanner
.
length
()>
0
){
social
.
add
(
socialScanner
);
System
.
out
.
println
(
"Voulez vous ajouter un autre réseau ? (si non tapez juste \"non\")"
);
String
answer
=
scanner
.
next
();
if
(
answer
.
equals
(
"non"
)){
System
.
out
.
println
(
"réseau ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
social
);
break
;
}
else
{
social
.
add
(
answer
);
}
}
}
// 1 x job ajouter dans un String
while
(
true
){
System
.
out
.
println
(
"Entrer la profession du contacte que vous voulez ajouter : "
);
String
jobScanner
=
scanner
.
nextLine
();
if
(
jobScanner
.
matches
(
"[a-zA-Z]+"
)
&&
jobScanner
.
length
()>
0
&&
jobScanner
.
length
()<
100
){
job
=
jobScanner
;
System
.
out
.
println
(
"job ajouter avec succès : "
);
System
.
out
.
println
(
"\t "
+
job
);
break
;
}
else
{
System
.
out
.
println
(
"job non ajouter car il ne respecte pas les standards (a-z A-Z, min 1 caractère max 100 caractère merci de rentrer un nom valide"
);
}
}
Contact
monContact
=
new
Contact
(
nom
,
prenomList
,
addresse
,
telephone
,
mail
,
social
,
job
);
list
.
add
(
monContact
);
Collections
.
sort
(
list
,
Comparator
.
comparing
(
Contact:
:
getNom
));
System
.
out
.
println
(
"Contacte ajouté avec succès"
);
}
else
if
(
userChoice
==
4
){
// quitter le programme
System
.
out
.
println
(
"A bientôt !"
);
break
;
}
else
{
System
.
out
.
println
(
"Erreur dans le choix du menu, merci de choisir une option parmi 1,2,3,4"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment