source: src/main/java/onetomany/bargainingchipsgame/Chip.java@ 265

Last change on this file since 265 was 264, checked in by Tim Baarslag, 5 years ago

Chip polished

File size: 1.4 KB
Line 
1package onetomany.bargainingchipsgame;
2
3import java.util.Random;
4
5import java.awt.Color;
6
7/**
8 * Chip is the fundamental element in Bargaining Chips.
9 * A chip could be assumed as any item at any scenario, e.g. Paracetamol in pharmaceutical market,
10 * a chair in furniture market, or a Red Dot.
11 * A chip=(color, unit price), where color is the id of the chip.
12 */
13public class Chip
14{
15 private String color;
16 private double price;
17
18 public Chip()
19 {
20 setRandomColor();
21 setRandomPrice(0, 10);
22 }
23
24 public Chip(String c, double p)
25 {
26 color = c;
27 price = p;
28 }
29
30 /**
31 * @return the color
32 */
33 public String getColor()
34 {
35 return color;
36 }
37
38 /**
39 * @return the price
40 */
41 public Double getPrice()
42 {
43 return price;
44 }
45
46
47 @Override
48 public String toString()
49 {
50 return "("+getColor()+", $"+getPrice().floatValue()+")";
51 }
52
53 public boolean hasSameColorAs(Stack s)
54 {
55 return getColor().equals(s.getColor());
56 }
57
58 public Color getRGBcolor()
59 {
60 return Color.decode(color);
61 }
62
63 private void setRandomColor()
64 {
65 String [] colors = new String [] {"Black", "Blue", "Cyan", "darkGray", "Gray", "lightGray", "Green", "Magenta", "Orange", "Pink", "Red", "White", "Yellow"};
66 int rnd = new Random().nextInt(colors.length);
67 color = colors[rnd];
68 }
69
70 public void setRandomPrice(double p1, double p2)
71 {
72 this.price = p1 + (p2 - p1) * new Random().nextDouble();
73 }
74}
Note: See TracBrowser for help on using the repository browser.