I would appreciate any help here.
executing the following code, Buyer2 ID always override buyers1 ID. Means I always get ID=2. I am not sure what is wrong with the following code. I think it is my enum and the get method which always retains the last value.
Buyer bOne = new Buyer("buyer1", 1);
Buyer bTwo = new Buyer("buyer2", 2);
rest of the code:
public enum Fruits {
Banana("banana", "B"),
Apple("apple","A"),
Orange("orange","O");
private String type, ID;
private Fruits(String type, String ID){
this.type = type;
this.ID = ID;
}
public String getType() {
return type;
}
public String getID() {
return ID;
}
public void setID(String ID){
this.ID = ID;
}
}
public class Player {
private String name;
private Fruits banana, apple, orange;
private int ID;
public buyer(String name, int ID) {
this.name = name;
this.ID = ID;
banana = Fruits.Orange;
apple = Fruits.Apple;
orange = Fruits.Orange;
banana.setID("B"+ID);
apple.setID("A"+ID);
Orange.setID="O"+ID;
}
}
thanks
Playerclass. Did you meanBuyer?enumdoesn't work like that. Withenum, there is only one Apple, only one Banana and only one Orange. Can you describe what you want your code to do?