Where are the items that are being counted to see if there are three of a kind? Should there be three variables that the code tests the contents of to see if they match?if there are three of a kind
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Where are the items that are being counted to see if there are three of a kind? Should there be three variables that the code tests the contents of to see if they match?if there are three of a kind
If you don't understand my answer, don't ignore it, ask a question.
What does that have to do with coding enum usage?
Post#24 shows a way to use enums.
Rewrite the code in post#23 to use that technique and show what you are trying to do.
Add some comments to document what the code is trying to do.
If you don't understand my answer, don't ignore it, ask a question.
That sounds like you need a loop to go through the contents of the ArrayList and count the number of times each item appears in the list.if the same enum(Infantry, Artillery, or Calvalry) appear three times in this ArrayList
If you don't understand my answer, don't ignore it, ask a question.
Please post the current version of the code that shows what problem you are having.
If you don't understand my answer, don't ignore it, ask a question.
package RiskProject;
public class Card{ //set for the Type of Countries public enum Country{ALASKA, ALBERTA, CENTRAL_AMERICA, EASTERN_UNITED_STATES, GREENLAND, NORTHWEST_TERRITORY, ONTARIO, QUEBEC, WESTERN_UNITED_STATES, ARGENTINA, BRAZIL, VENEZUELA, GREAT_BRITAIN, ICELAND, NORTHERN_EUROPE, SCANDINAVIA, SOUTHER_EUROPE, UKRAINE, WESTERN_EUROPE, CONGO, EAST_AFRICA, EGYPT, MADAGASCAR, NORTH_AFRICA, SOUTH_AFRICA, AFGHANISTAN, CHINA, INDIA, IRKUTSK, JAPAN, KAMCHATKA, MIDDLE_EAST, MONGOLIA, SIAM, SIBERIA, URAL, YAKUTSK, EASTERN_AUSTRALIA, INDONESIA, LOTR, NEW_GUINEA, WESTERN_AUSTRALIA}; //set for the Type of cards public enum Arms{INFANTRY, ARTILLERY, CALVALRY}; private final Country country; private final Arms arms; public Card(Country country, Arms arms){ this.country = country; this.arms = arms; } public @Override String toString(){ return country + "," + arms; } public Arms getArms(){ return arms; } public Country getCountry(){ return country; } }
package RiskProject; import java.util.ArrayList; import java.util.Collections; public class Deck{ private ArrayList<Card> deck; Card.Country[] countries = Card.Country.values(); Card.Arms[] arm = Card.Arms.values(); public Deck(){ deck = new ArrayList<Card>(); } public Card draw(){ return deck.remove(0); } public void add(){ for(Card.Arms arms : arm){ for(Card.Country country : countries){ deck.add(new Card(country, arms)); } } } public void shuffle(){ Collections.shuffle(deck); } }
package RiskProject; import java.util.ArrayList; public class Hand{ private final ArrayList<Card> deck; public int MAXCARDS = 4; Card.Arms[] arm = Card.Arms.values(); public Hand(){ deck = new ArrayList<Card>(); } public Card add(Card card){ deck.add(card); return card; } public Card removeCardsFromHand(int index1, int index2, int index3){ deck.remove(index1); deck.remove(index2); deck.remove(index3); return deck.get(index1); } public boolean canTurnInCards(){ for(int i = 0; i < deck.size(); i++){ deck.get(i); } } public boolean mustTurnInCards(){ if(deck.size() > MAXCARDS) return true; else return false; } public ArrayList<Card> getHand(){ return deck; } }
How do you test the code? I don't see a main() method.
If you don't understand my answer, don't ignore it, ask a question.