Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dev-oo
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mail Ladjali
dev-oo
Commits
679fc749
Commit
679fc749
authored
2 months ago
by
Mail Ladjali
Browse files
Options
Downloads
Patches
Plain Diff
tpoo-04::exo-extension
parent
d4e7b7e0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/tp04/Person.class
+0
-0
0 additions, 0 deletions
src/tp04/Person.class
src/tp04/Person.java
+30
-0
30 additions, 0 deletions
src/tp04/Person.java
src/tp04/UsePerson.java
+28
-0
28 additions, 0 deletions
src/tp04/UsePerson.java
with
58 additions
and
0 deletions
src/tp04/Person.class
0 → 100644
+
0
−
0
View file @
679fc749
File added
This diff is collapsed.
Click to expand it.
src/tp04/Person.java
0 → 100644
+
30
−
0
View file @
679fc749
package
tp04
;
public
class
Person
{
private
static
int
ID
;
private
String
forename
;
private
String
name
;
public
Person
(
String
forename
,
String
name
){
this
.
name
=
name
;
this
.
forename
=
forename
;
}
public
int
getID
(){
return
this
.
ID
;
}
public
String
toString
(){
return
"("
+
this
.
ID
+
":"
+
this
.
forename
+
this
.
name
+
")"
;
}
public
boolean
equals
(
Object
ID
){
if
(
this
==
ID
)
return
true
;
if
(
ID
==
null
)
return
false
;
if
(
this
.
getClass
()
!=
ID
.
getClass
())
return
false
;
Person
other
=
(
Person
)
ID
;
if
(
this
.
name
==
null
)
{
if
(
other
.
name
!=
null
)
return
false
;
}
else
if
(!
this
.
name
.
equals
(
other
.
name
))
return
false
;
if
(
this
.
forename
==
null
){
if
(
other
.
forename
!=
null
)
return
false
;
}
else
if
(!
this
.
forename
.
equals
(
other
.
forename
))
return
false
;
return
true
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tp04/UsePerson.java
0 → 100644
+
28
−
0
View file @
679fc749
package
tp04
;
public
class
UsePerson
{
public
static
void
main
(
String
[]
args
)
{
Person
alice
=
new
Person
(
"Alice"
,
"A"
);
Person
bruno
=
new
Person
(
"Bruno"
,
"B"
);
Person
autre
=
alice
;
boolean
testsOK
=
true
;
// test des getters
if
(!
alice
.
getForename
().
equals
(
"Alice"
)
||
!
alice
.
getName
().
equals
(
"A"
)
||
!
bruno
.
getForename
().
equals
(
"Bruno"
)
||
!
bruno
.
getName
().
equals
(
"B"
)
||
!
autre
.
getForename
().
equals
(
"Alice"
)
||
!
autre
.
getName
().
equals
(
"A"
))
{
System
.
out
.
println
(
"Erreur de méthodes GET"
);
testsOK
=
false
;
}
// test des setters
alice
.
setForename
(
"Anatole"
);
bruno
.
setName
(
"BB"
);
if
(!
alice
.
getForename
().
equals
(
"Anatole"
)
||
!
alice
.
getName
().
equals
(
"A"
)
||
!
bruno
.
getForename
().
equals
(
"Bruno"
)
||
!
bruno
.
getName
().
equals
(
"BB"
)
||
!
autre
.
getForename
().
equals
(
"Anatole"
)
||
!
autre
.
getName
().
equals
(
"A"
))
{
System
.
out
.
println
(
"Erreur de méthodes SET"
);
testsOK
=
false
;
}
// test du equals
if
(
alice
.
equals
(
bruno
)
||
!
alice
.
equals
(
autre
))
{
System
.
out
.
println
(
"Erreur de méthode equals"
);
testsOK
=
false
;
}
if
(
testsOK
)
System
.
out
.
println
(
"Tests de UsePerson réussis !"
);
}
}
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
register
or
sign in
to comment