I cannot get the properties of a certain card in this code it always prints null and I don't know why. I'm from Php-HTML world and I'm a newbie on JAVA.
This is the from Opportunity.java
package opportunity; import java.io.*; import java.util.Collections; import java.util.List; import static java.util.stream.Collectors.toList; import java.util.stream.IntStream; import java.util.stream.Stream; import opportunity.Card.CardType; public class Opportunity { /*Player 1 */ public int p1_money = 10000; public int p1_card_d = 40; public int p1_card_h = 0; /*Player 2 */ public int p2_money = 10000; public int p2_card_d = 40; public int p2_card_h = 0; /** * @param args the command line arguments * @throws java.io.IOException */ public static void main(String[] args) throws IOException { System.out.print("***************Opportunity***************\n"); final Card card1 = new Card(Card.CardType.EVENT, "Get Tax Returns"). setProperty("cost", "0.00"). setProperty("Effect", "Effect: Earn money equal to the\n" + "maximum income each of your\n" + "properties can give you,\n" + "depending on their level."); final Card card2 = new Card(Card.CardType.EVENT, "BIR Hunting Begins"). setProperty("cost", "0.00"). setProperty("Effect", "Effect: An opponent loses\n" + "money equal to 50% of the\n" + "maximum income each of\n" + "their properties can give him or her,\n" + "depending on the level of the\n" + "property."); final Card card3 = new Card(Card.CardType.EVENT, "Restore Balance"). setProperty("cost", "10000.00"). setProperty("Effect", "Effect: The total income of all\n" + "the players becomes equal to\n" + "the income of the player\n" + "with the lowest income."); final List<Card> deck = Stream.of(CardType.values()). flatMap(type -> IntStream.rangeClosed(1, 4).mapToObj(num -> new Card(type, "CardName" + num))). collect(toList()); Collections.shuffle(deck); System.out.println(deck.get(0).getProperty("Effect")); } } And This is the codes from Card.java
package opportunity; import java.util.*; public class Card { public enum CardType { EVENT, PROPERTY, ASSET; } private final CardType cardType; private final String cardName; private final Map<String, String> properties = new HashMap<>(); Card(final CardType cardType, final String cardName) { this.cardType = cardType; this.cardName = cardName; } public Card setProperty(final String name, final String value) { properties.put(name, value); return this; } public String getProperty(final String name) { return properties.get(name); } } It always returns this:
run: ***************Opportunity*************** null BUILD SUCCESSFUL (total time: 0 seconds) even though I put an index on get()
addto anArrayList.