added old projects

This commit is contained in:
Austin Bennett
2026-02-03 08:18:39 -06:00
parent 43acf989bf
commit 2451448b8a
623 changed files with 28117 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin"
}
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+57
View File
@@ -0,0 +1,57 @@
public class Card
{
public enum SuitT
{
CLUBS ("Clubs"), DIAMONDS("Diamonds"), HEARTS("Hearts"), SPADES("Spades");
private final String description;
private SuitT(String value) { description = value; }
public String getDescription() { return description; }
}
public enum FaceT
{
ACE ("Ace", 1),
TWO ("Two", 2),
THREE ("Three", 3),
FOUR ("Four", 4),
FIVE ("Five", 5),
SIX ("Six", 6),
SEVEN ("Seven", 7),
EIGHT ("Eight", 8),
NINE ("Nine", 9),
TEN ("Ten", 10),
JACK ("Jack", 11),
QUEEN ("Queen", 12),
KING ("King", 13);
private final String description;
private final int value;
private FaceT(String desc, int val)
{
description = desc;
value = val;
}
public String getDescription() { return description; }
public int getValue() { return value; }
}
private SuitT suit;
private FaceT faceValue;
public Card(SuitT suit, FaceT face)
{
this.suit = suit;
this.faceValue = face;
}
public String toString()
{
return faceValue.getDescription() + " of " + this.suit.getDescription();
}
}
+97
View File
@@ -0,0 +1,97 @@
import java.util.Random;
public class Deck
{
private final int DECK_SIZE = 52;
private Card[] _deck;
// Top of the deck is index 0; bottom is index 51.
private int currentTop;
//
// Allocates a default deck of 52 cards with four suits.
//
public Deck()
{
_deck = new Card[DECK_SIZE];
currentTop = 0;
int index = 0;
for (Card.SuitT suit : Card.SuitT.values())
{
for (Card.FaceT face : Card.FaceT.values())
{
_deck[index++] = new Card(suit, face);
}
}
}
//
// May assume a full deck.
//
// Shuffles by switching two random cards in the deck many times.
//
public void shuffle()
{
Random rng = new Random();
final int ITERATIONS = 1000;
for (int count = 0; count < ITERATIONS; count++) {
int firstCard = rng.nextInt(52);
int secondCard = rng.nextInt(52);
Card tempCard = _deck[firstCard];
_deck[firstCard] = _deck[secondCard];
_deck[secondCard] = tempCard;
}
}
//
// Computes the number of cards that remain in the deck:
// deck count minus the current top index
//
public int cardsRemaining()
{
return DECK_SIZE - currentTop;
}
//
// Returns the top card from the deck.
//
public Card deal() throws DeckException
{
if(currentTop >= DECK_SIZE) {
throw new DeckException("Empty Deck");
}
currentTop++;
return _deck[currentTop];
}
//
// Returns the top card from the deck.
//
public Card[] deal(int numCards) throws DeckException
{
Card[] dealCard = new Card[numCards];
for (int i = 0; i < numCards; i++) {
Card card = deal();
dealCard[i] = card;
}
return dealCard;
}
//
// Builds and returns a meaningful representation of the cards that
// remain in the deck.
//
public String toString()
{
String retStr = "";
for (int i = currentTop; i < DECK_SIZE; i++) {
retStr += _deck[i].toString() + ", ";
}
return retStr + "\n";
}
}
+9
View File
@@ -0,0 +1,9 @@
public class DeckException extends Exception
{
public DeckException(String msg)
{
super(msg);
}
}
+35
View File
@@ -0,0 +1,35 @@
public class Lab18
{
public static void main(String[] args)
{
Deck deck = new Deck();
System.out.println("Original Deck:");
System.out.println(deck);
deck.shuffle();
System.out.println("Shuffled Deck:");
System.out.println(deck);
Card[] hand = null;
try
{
hand = deck.deal(50);
}
catch(DeckException e)
{
}
System.out.println("Cards in the hand: ");
for (Card card : hand)
{
System.out.println(card);
}
System.out.println();
System.out.println("Cards remaining in the deck: ");
System.out.println(deck);
}
}