Replacing userinput with the card index
presented on a new row, and is not replacing the actual number the user typed. I've tried to put the letter and the number in the same arraylist but I have no idea how to display these.
presented on a new row, and is not replacing the actual number the user typed. I've tried to put the letter and the number in the same arraylist but I have no idea how to display these.
one thing I see you should replace String secondCardLetter = card.getCardLetter();
with String secondCardLetter = deck.getCards(i);
otherwise second card is same as first try that and let me know
Also recommend replacing ArrayList<Card> card = new ArrayList<Card>();
with List<Card> cards = new ArrayList<Card>();
please note the variable name change too since its a collection of Card(s). Initialize the deck with a loop
char A = 'A';
int repeats = 2, numOfCards = 8;
for ( int i = 0; i<numOfCards;i++){
for (int j = 0; j<repeats; j++){
cards.add(new Card((char) ( A + i ) + "",i+1,""));
}
}
Please pay attention to your names as the to depict what the method may be doing. You getCards
method takes an integer and returns the "Card", where as getCards shouldnt take any parameters and simply return the cards list you have stored. If you want to return a specific card, declare a method called public Card getCard(int i)
notice the missing letter s as it shows this will return one card, and on the other hand public List<Card> getCards()
method would return a List of cards, then that for loop would work.
If I understand you correctly, what you are looking to do is to keep replacing the characters in the terminal output, without breaking the output into new lines right? i.e: a counter going from 1 to 100?
For that you need to use the carriage return character: '\r'
I think this is the line you are printing the letter of the card right?
System.out.println(format("%10s","\n[ " + firstCardLetter + " ]"));
Try changing this to
System.out.println(format("%10s","\r[ " + firstCardLetter + " ]"));
edit
Sorry what you have to use is the \033[F
character, as mentioned here
System.out.println(format("%10s","\033[F[ " + firstCardLetter + " ]"));