diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index d47a2a3..21aea67 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -7,6 +7,8 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Random; public class Shop { public ArrayList allItems; @@ -14,6 +16,7 @@ public class Shop { public Shop(){ allItems = loadItems(); + currentShopItems = itemRotation(allItems, 2); } public boolean buy(){ @@ -41,10 +44,18 @@ public class Shop { return arrayList; } - public ArrayList itemRotation(ArrayList alleItems, int itemCount){ - //ToDo - - return null; + public ArrayList itemRotation(ArrayList alleItems, int itemCount){ + ArrayList arrayList = new ArrayList(); + HashSet hashSet = new HashSet<>(); + Random random = new Random(); + while (hashSet.size() < itemCount){ + int rand = random.nextInt(alleItems.size()); + if(!hashSet.contains(rand)){ + hashSet.add(rand); + arrayList.add(alleItems.get(rand)); + } + } + return arrayList; } public void getCurrentShopItems(){