IT retraining Week fifteen: Data Structures and Enums
It's gotten really cold, and I'm already wearing my coat. But I don't actually want to talk about the weather.
It's time again for the weekly recap of my retraining program. This week was a bit disorganized because companies came to introduce themselves to us. This has to do with the internships that are still ahead of us. A few companies – including some internal ones – would like to take on interns from our retraining program. The chances of securing a job offer afterward are good with the companies that come to us. However, of course, there are only a limited number of internship positions available, and due to the current poor economic situation, fewer companies came this year than in previous years. I already have a top three list in my head, but nothing is set yet. Next week, there’s at least one more presentation scheduled. Because of these company presentations, classes were often fragmented. On the first day, we were given a review assignment, as an alarming number of Java concepts had faded during the SQL module. So, we worked on this task whenever we had time. We also learned a few more data structures, such as Maps and Stacks. On Friday, we were given another assignment on these, which we’re supposed to review on Monday (tomorrow). The task once again involves implementing a console application, this time representing a stack of playing cards. We used enums for card suits and values – enums were also a new topic this week. So, we assign a random suit and value to a general card object; a deck object has a certain number of cards, and it should also be able to be shuffled.
I felt a bit overwhelmed with it and wasn’t the only one. I didn’t finish and spent some time working on it yesterday.
Deck.java
// Initialize and build/generate a deck
cardDeck = new LinkedList<>();
buildDeck();
}
// Generates all the combinations of colors and values
private void buildDeck() {
for (CardColor color : CardColor.values()) {
for (Value value : Value.values()) {
cardDeck.add(new Card(color, value));
}
}
}
// Shuffles the deck
public void shuffle() { // there's a shuffle method already in Java
Collections.shuffle(cardDeck);
System.out.println("Deck has been shuffled.");
}
// Draws a card from the top
public Card drawCard() {
if (!cardDeck.isEmpty()) { // If the deck isn't empty...
return cardDeck.pop(); // ...reveal a card
} else { // Otherwise, this message appears:
System.out.println("The deck is empty!");
return null;
}
}
Enums
// Colors.java
CLUBS('\u2663'), // Unicode symbols :-)
SPADES('\u2660'),
DIAMONDS('\u2666'),
HEARTS('\u2665');
private char cardColor;
// Values.java
ACE("A"),
TWO("2"),
THREE("3"),
FOUR("4"),
FIVE("5"),
SIX("6"),
SEVEN("7"),
EIGHT("8"),
NINE("9"),
TEN("10"),
JACK("J"),
QUEEN("Q"),
KING("K");
private final String symbol;
I haven’t compiled my notes from class yet, since I wanted to do a weekly summary. But I don’t want to do that here because, firstly, it's not very effective for me, and secondly, I don’t feel like working on it right now.
So, I guess that’s it for today.
Music: -
Mood: sluggish