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

Last change on this file since 256 was 253, checked in by Faria Nassiri Mofakham, 5 years ago

Commit #1 of:
+ negotiator.onetomany package refactored into onetomany package.
+ info created for all contained the packages.
+ current work defined under onetomany.bargainingchipsgame.
+ in this package, onetomany.bargainingchipsgame.players package includes packages for utility function, coordinator, negotiatior, and buyer and seller.
+ negotiator.onetomany package now contains nothing, can be deleted.
+ Interaction thread

File size: 2.6 KB
Line 
1/**
2 * Chip class
3 */
4package onetomany.bargainingchipsgame;
5
6import java.awt.Color;
7import java.util.Arrays;
8import java.util.List;
9import java.util.Random;
10
11/**
12 * Chip is the fundamental element of the market domain in Bargaining Chips Game.
13 * 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.
14 * A chip=(color, unit price), where color is the id of the chip.
15 *
16 * @author Faria Nassiri-Mofakham
17 */
18
19public class Chip
20{
21
22 private String color;
23 private double price;
24
25 public Chip()
26 {
27 setColor(null);
28 setPrice(-1);
29 }
30
31 public Chip(String c, double p)
32 {
33 setColor(c);
34 setPrice(p);
35 }
36
37 /**
38 * @param c the color to set
39 */
40
41 public void setColor(String c)
42 {
43 this.color = c;
44 }
45
46 /**
47 * @param p the price to set
48 */
49 public void setPrice(double p)
50 {
51 this.price = p;
52 }
53
54 public void setRandomPrice(double p1, double p2)
55 {
56 this.price = p1 + (p2 - p1) * new Random().nextDouble();
57 }
58
59 /**
60 * @return the color
61 */
62 public String getColor()
63 {
64 return color;
65 }
66
67 /**
68 * @return the price
69 */
70 public Double getPrice()
71 {
72 return price;
73 }
74
75
76 @Override
77 public String toString()
78 {
79 return "("+getColor()+","+getPrice().floatValue()+"$)";
80 // other representations
81 //return this.getClass().getSimpleName()+"("+getColor()+","+getPrice().floatValue()+"$)";
82 // // return getColor()+" "+this.getClass().getSimpleName()+" for "+getPrice()+"$";
83 }
84
85 public Color getRGBcolor(String s) // to be able to pass colors in RGB hex strings
86 {
87 return Color.decode(s);
88 }
89
90 public void setColorRandomRGB()
91 {
92 this.color = new Color((int)(Math.random()*255+1),(int)(Math.random()*255+1),(int)(Math.random()*255+1)).toString();
93 }
94
95 public void setRandomColor()
96 {
97 int i = (int)(Math.random()*13);
98 switch(i)
99 {
100 case 0:
101 this.color="Black";
102 break;
103 case 1:
104 this.color="Blue";
105 break;
106 case 2:
107 this.color="Cyan";
108 break;
109 case 3:
110 this.color="darkGray";
111 break;
112 case 4:
113 this.color="Gray";
114 break;
115 case 5:
116 this.color="lightGray";
117 break;
118 case 6:
119 this.color="Green";
120 break;
121 case 7:
122 this.color="Magenta";
123 break;
124 case 8:
125 this.color="Orange";
126 break;
127 case 9:
128 this.color="Pink";
129 break;
130 case 10:
131 this.color="Red";
132 break;
133 case 11:
134 this.color="White";
135 break;
136 case 12:
137 this.color="Yellow";
138 break;
139
140 default:
141 System.out.println(i+" Undefined color!");
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.