Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PDN-S2
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
Robin VAN DE MERGHEL
PDN-S2
Commits
86f913d7
Commit
86f913d7
authored
Mar 2, 2023
by
Robin VAN DE MERGHEL
Browse files
Options
Downloads
Patches
Plain Diff
OOP course (in class)
parent
1513c96d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
POO/TD/TD2/pdn.md
+79
-0
79 additions, 0 deletions
POO/TD/TD2/pdn.md
with
79 additions
and
0 deletions
POO/TD/TD2/pdn.md
+
79
−
0
View file @
86f913d7
...
...
@@ -67,3 +67,82 @@ digraph {
Carrosserie
->
Porte
[
label
=
"2..4"
]
;
}
```
# Question 3
On implémente la classe
`Voiture`
en Java.
```
java
public
class
Carrosserie
{
private
Porte
[]
portes
;
public
Carrosserie
(
int
nbPortes
)
{
if
(
nbPortes
<
2
||
nbPortes
>
4
)
throw
new
IllegalArgumentException
(
"Le nombre de portes doit être compris entre 2 et 4."
);
}
this
.
portes
=
new
Porte
[
nbPortes
];
for
(
int
i
=
0
;
i
<
nbPortes
;
i
++)
{
this
.
portes
[
i
]
=
new
Porte
();
}
}
}
```
```
java
abstract
class
Voiture
{
private
Carrosserie
carrosserie
;
protected
Roue
[]
roues
;
abstract
int
nbRoues
();
public
Voiture
(
int
nbPortes
)
{
this
.
carrosserie
=
new
Carrosserie
(
nbPortes
);
this
.
initRoues
();
}
private
void
initRoues
()
{
this
.
roues
=
new
Roue
[
nbRoues
()];
for
(
int
i
=
0
;
i
<
nbRoues
;
i
++)
{
this
.
roues
[
i
]
=
new
Roue
();
}
}
}
```
```
java
class
VoitureA
extends
Voiture
{
private
Moteur
moteur
;
public
VoitureA
(
int
nbPortes
)
{
super
(
nbPortes
);
}
@Override
int
nbRoues
()
{
return
4
;
}
}
```
```
java
\ No newline at end of file
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