Commit f205386a authored by Markus Klinik's avatar Markus Klinik
Browse files

update start project

parent ebfdb79c
......@@ -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 numberOfArticles;
private final int numberOfItemsWanted;
private final static Random GENERATOR = new Random();
public int getNumberOfItemsWanted() {
return numberOfItemsWanted;
}
public Customer(int number, Store store) {
this.store = store;
customerNumber = number;
numberOfArticles = GENERATOR.nextInt(MAX_ITEMS) + 1;
numberOfItemsWanted = GENERATOR.nextInt(MAX_ITEMS) + 1;
}
@Override
public Integer call() {
return -1;
int numberOfItemsBought = 0;
return numberOfItemsBought;
}
}
......@@ -10,7 +10,7 @@ import java.util.stream.IntStream;
public class Main {
private static final int NR_OF_CLIENTS = 30;
private static final int NR_OF_CLIENTS = 100;
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.");
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment