/** * Chip class */ package onetomany.bargainingchipsgame; import java.awt.Color; import java.util.Arrays; import java.util.List; import java.util.Random; /** * Chip is the fundamental element of the market domain in Bargaining Chips Game. * 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. * * @author Faria Nassiri-Mofakham */ public class Chip { private String color; private double price; public Chip() { setColor(null); setPrice(-1); } public Chip(String c, double p) { setColor(c); setPrice(p); } /** * @param c the color to set */ public void setColor(String c) { this.color = c; } /** * @param p the price to set */ public void setPrice(double p) { this.price = p; } public void setRandomPrice(double p1, double p2) { this.price = p1 + (p2 - p1) * new Random().nextDouble(); } /** * @return the color */ public String getColor() { return color; } /** * @return the price */ public Double getPrice() { return price; } @Override public String toString() { return "("+getColor()+","+getPrice().floatValue()+"$)"; // other representations //return this.getClass().getSimpleName()+"("+getColor()+","+getPrice().floatValue()+"$)"; // // return getColor()+" "+this.getClass().getSimpleName()+" for "+getPrice()+"$"; } public Color getRGBcolor(String s) // to be able to pass colors in RGB hex strings { return Color.decode(s); } public void setColorRandomRGB() { this.color = new Color((int)(Math.random()*255+1),(int)(Math.random()*255+1),(int)(Math.random()*255+1)).toString(); } public void setRandomColor() { int i = (int)(Math.random()*13); switch(i) { case 0: this.color="Black"; break; case 1: this.color="Blue"; break; case 2: this.color="Cyan"; break; case 3: this.color="darkGray"; break; case 4: this.color="Gray"; break; case 5: this.color="lightGray"; break; case 6: this.color="Green"; break; case 7: this.color="Magenta"; break; case 8: this.color="Orange"; break; case 9: this.color="Pink"; break; case 10: this.color="Red"; break; case 11: this.color="White"; break; case 12: this.color="Yellow"; break; default: System.out.println(i+" Undefined color!"); } } }