package onetomany.bargainingchipsgame; import java.util.Random; import java.awt.Color; /** * Chip is the fundamental element in Bargaining Chips. * A chip could be assumed as any item at any scenario, e.g. Paracetamol in pharmaceutical market, * a chair in furniture market, or a Red Dot. * A chip=(color, unit price), where color is the id of the chip. */ public class Chip { private String color; private double price; public Chip() { setRandomColor(); setRandomPrice(0, 10); } public Chip(String c, double p) { color = c; price = p; } /** * @return the color */ public String getColor() { return color; } /** * @return the price */ public Double getPrice() { return price; } @Override public String toString() { return "("+getColor()+", $"+getPrice().floatValue()+")"; } public boolean hasSameColorAs(Stack s) { return getColor().equals(s.getColor()); } public Color getRGBcolor() { return Color.decode(color); } private void setRandomColor() { String [] colors = new String [] {"Black", "Blue", "Cyan", "darkGray", "Gray", "lightGray", "Green", "Magenta", "Orange", "Pink", "Red", "White", "Yellow"}; int rnd = new Random().nextInt(colors.length); color = colors[rnd]; } public void setRandomPrice(double p1, double p2) { this.price = p1 + (p2 - p1) * new Random().nextDouble(); } }