Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
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
Ethan Robert
dev-oo
Commits
cbc575ec
Commit
cbc575ec
authored
2 months ago
by
Ethan Robert
Browse files
Options
Downloads
Patches
Plain Diff
Added ToDoList (unfinished)
parent
4cc9e43d
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/tp03/Task.java
+13
-1
13 additions, 1 deletion
src/tp03/Task.java
src/tp03/ToDoList.java
+122
-0
122 additions, 0 deletions
src/tp03/ToDoList.java
src/tp03/UseToDoList.java
+41
-0
41 additions, 0 deletions
src/tp03/UseToDoList.java
with
176 additions
and
1 deletion
src/tp03/Task.java
+
13
−
1
View file @
cbc575ec
...
...
@@ -27,7 +27,7 @@ public class Task {
}
public
Task
(
String
description
,
LocalDate
creation
,
LocalDate
deadline
,
int
duration
)
{
this
.
taskID
=
Task
.
counter
=
this
.
taskID
=
Task
.
counter
;
Task
.
counter
++;
this
.
creationDate
=
creation
;
...
...
@@ -68,4 +68,16 @@ public class Task {
public
void
delay
(
int
nbDays
)
{
this
.
deadline
=
this
.
deadline
.
plusDays
(
nbDays
);
}
public
LocalDate
getDeadline
()
{
return
this
.
deadline
;
}
public
LocalDate
getCreationDate
()
{
return
this
.
creationDate
;
}
public
int
getDuration
()
{
return
this
.
duration
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tp03/ToDoList.java
0 → 100644
+
122
−
0
View file @
cbc575ec
package
tp03.ex02
;
import
java.util.Arrays
;
import
java.time.LocalDate
;
public
class
ToDoList
{
private
Task
[]
chores
;
public
ToDoList
()
{
this
.
chores
=
new
Task
[
5
];
}
public
void
enlarge
()
{
this
.
chores
=
Arrays
.
copyOf
(
this
.
chores
,
this
.
chores
.
length
+
5
);
}
public
String
toString
()
{
String
result
=
""
+
this
.
getNbTask
()
+
" tasks: \n"
;
for
(
int
i
=
0
;
i
<
this
.
chores
.
length
;
i
++)
{
if
(
this
.
chores
[
i
]
!=
null
)
{
result
+=
" - "
+
this
.
chores
[
i
]
+
"\n"
;
}
}
return
result
;
}
public
void
addTask
(
Task
task
)
{
boolean
added
=
false
;
for
(
int
i
=
0
;
i
<
this
.
chores
.
length
;
i
++)
{
if
(
this
.
chores
[
i
]
==
null
&&
!
added
)
{
this
.
chores
[
i
]
=
task
;
added
=
true
;
}
}
// Enlarge if full
if
(!
added
)
{
this
.
enlarge
();
this
.
chores
[
this
.
chores
.
length
-
5
]
=
task
;
}
}
public
void
removeTask
(
int
index
)
{
this
.
chores
[
index
]
=
null
;
}
public
boolean
isOverwhelmed
()
{
return
this
.
getNbTask
()
==
this
.
chores
.
length
;
}
public
int
getNbTask
()
{
int
nb
=
0
;
for
(
int
i
=
0
;
i
<
this
.
chores
.
length
;
i
++)
{
if
(
this
.
chores
[
i
]
!=
null
)
{
nb
++;
}
}
return
nb
;
}
public
void
onSickLeave
(
int
days
)
{
for
(
int
i
=
0
;
i
<
this
.
chores
.
length
;
i
++)
{
if
(
this
.
chores
[
i
]
!=
null
)
{
this
.
chores
[
i
].
delay
(
days
);
}
}
}
public
void
emergencySort
()
{
int
n
=
this
.
chores
.
length
;
for
(
int
i
=
1
;
i
<
n
;
i
++)
{
Task
cle
=
this
.
chores
[
i
];
int
j
=
i
-
1
;
// Déplace les éléments du tableau[0..i-1] qui sont supérieurs à clé
while
(
j
>=
0
&&
this
.
chores
[
j
].
getDeadline
().
isAfter
(
cle
.
getDeadline
()))
{
this
.
chores
[
j
+
1
]
=
this
.
chores
[
j
];
j
=
j
-
1
;
}
this
.
chores
[
j
+
1
]
=
cle
;
}
}
public
void
senioritySort
()
{
int
n
=
this
.
chores
.
length
;
for
(
int
i
=
1
;
i
<
n
;
i
++)
{
Task
cle
=
this
.
chores
[
i
];
int
j
=
i
-
1
;
// Déplace les éléments du tableau[0..i-1] qui sont supérieurs à clé
while
(
j
>=
0
&&
this
.
chores
[
j
].
getCreationDate
().
isAfter
(
cle
.
getCreationDate
()))
{
this
.
chores
[
j
+
1
]
=
this
.
chores
[
j
];
j
=
j
-
1
;
}
this
.
chores
[
j
+
1
]
=
cle
;
}
}
public
void
durationSort
()
{
int
n
=
this
.
chores
.
length
;
for
(
int
i
=
1
;
i
<
n
;
i
++)
{
Task
cle
=
this
.
chores
[
i
];
int
j
=
i
-
1
;
// Déplace les éléments du tableau[0..i-1] qui sont supérieurs à clé
while
(
j
>=
0
&&
this
.
chores
[
j
].
getDuration
()
>
cle
.
getDuration
())
{
this
.
chores
[
j
+
1
]
=
this
.
chores
[
j
];
j
=
j
-
1
;
}
this
.
chores
[
j
+
1
]
=
cle
;
}
}
public
Task
[]
getTasks
()
{
return
this
.
chores
.
clone
();
}
public
Task
getTask
(
int
index
)
{
return
this
.
chores
[
index
];
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tp03/UseToDoList.java
0 → 100644
+
41
−
0
View file @
cbc575ec
package
tp03.ex02
;
import
java.time.LocalDate
;
public
class
UseToDoList
{
public
static
void
main
(
String
[]
args
)
{
ToDoList
Alice
=
new
ToDoList
();
ToDoList
Bruno
=
new
ToDoList
();
Alice
.
addTask
(
new
Task
(
"a1"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
3
),
1
));
Alice
.
addTask
(
new
Task
(
"a2"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
4
),
1
));
Alice
.
addTask
(
new
Task
(
"a3"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
5
),
1
));
Bruno
.
addTask
(
new
Task
(
"b1"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
1
),
1
));
Bruno
.
addTask
(
new
Task
(
"b2"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
5
),
1
));
Bruno
.
addTask
(
new
Task
(
"b3"
,
LocalDate
.
now
(),
LocalDate
.
now
().
plusDays
(
9
),
1
));
System
.
out
.
println
(
"Alice: "
+
Alice
);
System
.
out
.
println
(
"Bruno: "
+
Bruno
);
Task
[]
newAliceTasks
=
Bruno
.
getTasks
();
for
(
int
i
=
0
;
i
<
newAliceTasks
.
length
;
i
++)
{
Alice
.
addTask
(
newAliceTasks
[
i
]);
Bruno
.
removeTask
(
i
);
}
System
.
out
.
println
(
"Alice: "
+
Alice
);
System
.
out
.
println
(
"Bruno: "
+
Bruno
);
Alice
.
durationSort
();
Alice
.
getTask
(
Alice
.
getNbTask
()
-
1
).
delay
(
30
);
Alice
.
senioritySort
();
Alice
.
getTask
(
Alice
.
getNbTask
()
-
1
).
delay
(
30
);
System
.
out
.
println
(
"Alice: "
+
Alice
);
}
}
\ 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