Skip to content

Instantly share code, notes, and snippets.

@nekma555
Last active December 20, 2017 00:55
Show Gist options
  • Save nekma555/079de190cea064534c4b3bd16e7c371e to your computer and use it in GitHub Desktop.
Save nekma555/079de190cea064534c4b3bd16e7c371e to your computer and use it in GitHub Desktop.
BoxOpener
package com.company;
import java.util.Random;
public class Box {
private int size;
private int boxPrice = 5;
public static Item[] items;
BoxOpener b = new BoxOpener();
public int getBoxPrice() {
return boxPrice;
}
public int getTotalBoxValue() {
int sum = 0;
for (int i = 0; i < items.length; i++) {
Item temp = new Item();
items[i] = temp;
//System.out.println("This item's price is " + temp.getPrice() + ".");
sum += temp.getPrice();
}
return sum;
};
public int getSize() {
return this.size;
}
public Box() {
createSize();
createItems();
assignBoxPrice();
}
//constructor; will always give int boxesOpened, and must have that argument elsewhere.
public void createSize() {
int[] items = new int[]{1, 2, 3, 4, 5};
Random itempick = new Random();
this.size = items[itempick.nextInt(items.length)];
}
public void createItems() {
items = new Item[this.size];
for (int i = 0; i < this.size; i++) {
Item temp = new Item();
items[i] = temp;
}
}
public void assignBoxPrice() {
if(b.getBoxesOpened() >0 && (b.getBoxesOpened()%5)== 0){
boxPrice += 1;
System.out.println("Box price: "+getBoxPrice());
}
}
}
package com.company;
public class BoxOpener {
private int boxesOpened = 0;
private int boxesRemaining = 5;
Wallet w = new Wallet();
Box b = new Box();
public int getBoxesOpened() {
return boxesOpened;
}
public int getBoxesRemaining() {
return this.boxesRemaining;
}
public BoxOpener() {
while (boxesRemaining>0){
boxesRemaining -= 1;
boxesOpened += 1;
System.out.println("Boxes opened: "+getBoxesOpened());
w.addCash();
System.out.println("Cash: "+w.getCurrentMoney());
while(w.getCurrentMoney()>=b.getBoxPrice()){
w.subtractCash();
}
}
}
//this needs to move the value of box contents to wallet, keep track of boxes remaining and boxes opened, and buy boxes when wallet has enough money.
}
package com.company;
import java.util.Random;
public class Item {
private int itemPrice;
public int getPrice() {
return this.itemPrice;
}
public Item() {createItemPrice();}
public void createItemPrice(){
int[]prices = new int[]{1, 2, 3, 4, 5};
Random pricepick = new Random();
this.itemPrice = prices[pricepick.nextInt(prices.length)];
}
}
package com.company;
public class LootBox {
public static void main(String[] args) {
}
}
//open boxes, get x items, sell for money, buy more boxes. repeat until run out of money.*/
package com.company;
public class Wallet {
private int currentMoney = 0;
Box b1 = new Box();
public int getCurrentMoney(){
currentMoney += b1.getTotalBoxValue();
return currentMoney;
}
public Wallet() {
}
public void addCash(){
this.currentMoney += b1.getTotalBoxValue();
}
public void subtractCash(){
this.currentMoney -= b1.getBoxPrice();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment