Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pieter Koopman
Personal Prof public repository
Commits
f205386a
Commit
f205386a
authored
Feb 17, 2020
by
Markus Klinik
Browse files
update start project
parent
ebfdb79c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/test-data/assignment15-supermarket-start/src/supermarket/Customer.java
View file @
f205386a
...
...
@@ -8,17 +8,22 @@ public class Customer implements Callable<Integer> {
public
static
final
int
MAX_ITEMS
=
20
;
private
final
Store
store
;
private
final
int
customerNumber
;
private
final
int
numberOf
Articles
;
private
final
int
numberOf
ItemsWanted
;
private
final
static
Random
GENERATOR
=
new
Random
();
public
int
getNumberOfItemsWanted
()
{
return
numberOfItemsWanted
;
}
public
Customer
(
int
number
,
Store
store
)
{
this
.
store
=
store
;
customerNumber
=
number
;
numberOf
Articles
=
GENERATOR
.
nextInt
(
MAX_ITEMS
)
+
1
;
numberOf
ItemsWanted
=
GENERATOR
.
nextInt
(
MAX_ITEMS
)
+
1
;
}
@Override
public
Integer
call
()
{
return
-
1
;
int
numberOfItemsBought
=
0
;
return
numberOfItemsBought
;
}
}
src/test-data/assignment15-supermarket-start/src/supermarket/Main.java
View file @
f205386a
...
...
@@ -10,7 +10,7 @@ import java.util.stream.IntStream;
public
class
Main
{
private
static
final
int
NR_OF_CLIENTS
=
3
0
;
private
static
final
int
NR_OF_CLIENTS
=
10
0
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ExecutorService
executor
=
Executors
.
newCachedThreadPool
();
...
...
@@ -21,8 +21,12 @@ public class Main {
List
<
Customer
>
customers
=
IntStream
.
range
(
0
,
NR_OF_CLIENTS
).
mapToObj
(
i
->
new
Customer
(
i
,
store
))
.
collect
(
Collectors
.
toList
());
List
<
Future
<
Integer
>>
customerResults
=
executor
.
invokeAll
(
customers
);
int
result
=
0
;
int
totalItemsSold
=
0
;
System
.
out
.
println
(
"All customers are done. "
+
result
+
" items sold."
);
int
totalItemsWanted
=
customers
.
stream
().
mapToInt
(
Customer:
:
getNumberOfItemsWanted
).
sum
();
System
.
out
.
println
(
"All customers are done."
);
System
.
out
.
println
(
totalItemsWanted
+
" items wanted."
);
System
.
out
.
println
(
totalItemsSold
+
" items sold."
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment