diff --git a/Code/Age/.vscode/settings.json b/Code/Age/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Code/Age/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Code/Age/README.md b/Code/Age/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Code/Age/README.md @@ -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). diff --git a/Code/Age/bin/App.class b/Code/Age/bin/App.class new file mode 100644 index 0000000..73a4dc0 Binary files /dev/null and b/Code/Age/bin/App.class differ diff --git a/Code/Age/src/App.class b/Code/Age/src/App.class new file mode 100644 index 0000000..7b02030 Binary files /dev/null and b/Code/Age/src/App.class differ diff --git a/Code/Age/src/App.java b/Code/Age/src/App.java new file mode 100644 index 0000000..5d8a1dd --- /dev/null +++ b/Code/Age/src/App.java @@ -0,0 +1,30 @@ +import java.util.Scanner; + +public class App { + public static void main(String[] args) throws Exception { + double ageParent = 0; + double ageChild = 0; + + ageParent = getInput("Parent"); + ageChild = getInput("Child"); + + System.out.println("Calculating when the child is half the age of the parent"); + + for (double x = 0; x >= 0; x++) { + if ((ageParent + x) / 2 == ageChild + x) { + ageChild += x; + ageParent += x; + System.out.println("age of the child: " + ageChild); + System.out.println("age of the parent: " + ageParent); + System.out.println("That will be in " + x + " years"); + break; + } + } + } + + public static int getInput(String x) { + Scanner scan = new Scanner(System.in); + System.out.print("Enter the age of " + x + ": "); + return scan.nextInt(); + } +} diff --git a/Code/codinGame/.vscode/settings.json b/Code/codinGame/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Code/codinGame/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Code/codinGame/README.md b/Code/codinGame/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Code/codinGame/README.md @@ -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). diff --git a/Code/codinGame/src/App.java b/Code/codinGame/src/App.java new file mode 100644 index 0000000..0a839f9 --- /dev/null +++ b/Code/codinGame/src/App.java @@ -0,0 +1,5 @@ +public class App { + public static void main(String[] args) throws Exception { + System.out.println("Hello, World!"); + } +} diff --git a/Code/gambling/bin/App.class b/Code/gambling/bin/App.class index 22c5ba3..f699288 100644 Binary files a/Code/gambling/bin/App.class and b/Code/gambling/bin/App.class differ diff --git a/Code/gambling/bin/Gambling.pap b/Code/gambling/bin/Gambling.pap new file mode 100644 index 0000000..b48b2f2 --- /dev/null +++ b/Code/gambling/bin/Gambling.pap @@ -0,0 +1,346 @@ + + + + + + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ budget]]> +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + +
+
+
+ \ No newline at end of file diff --git a/Code/gambling/src/App.java b/Code/gambling/src/App.java index c5d740d..9ef8c8f 100644 --- a/Code/gambling/src/App.java +++ b/Code/gambling/src/App.java @@ -1,13 +1,19 @@ +import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class App { - public static int Budget = 1000; + public static int Budget = 0; + public static boolean card[][] = new boolean[4][13]; + public static int turnCount = 0; + public static final int MIN_TURNS = 3; + public static final int MAX_TURNS = 10; public static void main(String[] args) { + initializeBet(); while (true) { System.out.println("1. Coinflip, 2. Blackjack, 3. Roulette"); - int input = getInput(); + int input = getInput("Enter choice: "); switch (input) { case 1: playCoinflip(); @@ -25,53 +31,284 @@ public class App { } } - public static int getInput() { + public static void printRules() { + System.out.println("Welcome to Blackjack!"); + System.out.println("Rules:"); + System.out.println("1. The goal is to get as close to 21 without exceeding it."); + System.out.println("2. Aces can be 1 or 11, face cards are worth 10, and other cards are worth their number."); + System.out.println("3. You start by placing a bet before receiving your first two cards."); + System.out.println("4. Options:"); + System.out.println(" - Hit: Draw another card."); + System.out.println(" - Stand: Keep your current hand."); + System.out.println(" - Double Down: Double your bet and receive one more card."); + System.out.println(" - Split: If you have two cards of the same value, split them into two hands."); + System.out.println("5. The dealer will draw cards until they have at least 17 points."); + System.out.println("6. Cards will be reshuffled after 3-10 turns."); + System.out.println("Good luck!\n"); + } + + public static int getInput(String text) { Scanner scan = new Scanner(System.in); - System.out.print("Enter your choice: "); + System.out.print(text); return scan.nextInt(); } + public static void initializeBet() { + Budget = getInput("With how much money do you want to play? "); + printBudget(); + } + public static void playCoinflip() { - Scanner scan = new Scanner(System.in); Random random = new Random(); while (true) { - System.out.print("Enter your bet: "); - int bet = scan.nextInt(); - if (bet > Budget) { - System.out.println("You don't have enough money."); - return; - } - - System.out.print("Enter 1 for heads or 2 for tails: "); - int choice = scan.nextInt(); + int bet = enterBet(); + int choice = getInput("Enter 1 for heads or 2 for tails (0 to stop playing): "); int result = random.nextInt(2) + 1; - - if (choice == result) { - Budget += bet; - System.out.println("You won!"); + if (choice == 0) { + break; } else { - Budget -= bet; - System.out.println("You lost."); + if (choice == result) { + Budget += bet; + System.out.println("You won!"); + } else { + Budget -= bet; + System.out.println("You lost."); + } + printBudget(); } - printBudget(); } } public static void playBlackjack() { - // Placeholder for Blackjack game logic - System.out.println("Blackjack game coming soon..."); - // Update budget here based on game result - printBudget(); + ArrayList playerHands = new ArrayList<>(); + ArrayList playerAceCounts = new ArrayList<>(); + ArrayList bets = new ArrayList<>(); + boolean dealerDone = false; + + printRules(); // Print the rules at the start of the Blackjack game + shuffleCards(); // Initial shuffle + + while (true) { + // Reshuffle if needed + if (turnCount >= MIN_TURNS && turnCount <= MAX_TURNS + && turnCount % (new Random().nextInt(MAX_TURNS - MIN_TURNS + 1) + MIN_TURNS) == 0) { + shuffleCards(); + } + + System.out.println("Starting new hand..."); + bets.clear(); + playerHands.clear(); + playerAceCounts.clear(); + + bets.add(enterBet()); + playerHands.add(getCard()); + playerHands.set(0, playerHands.get(0) + getCard()); + playerAceCounts.add(0); + + for (int i = 0; i < playerHands.size(); i++) { + boolean handDone = false; + + while (!handDone) { + System.out.println("Your hand " + (i + 1) + ": " + playerHands.get(i)); + System.out.println("1. Hit 2. Stand 3. Double Down 4. Split"); + int choice = getInput("Choose an action: "); + + switch (choice) { + case 1: // Hit + playerHands.set(i, playerHands.get(i) + + getCardWithAceHandling(playerHands.get(i), playerAceCounts.get(i))); + if (playerHands.get(i) > 21) { + System.out.println("You busted!"); + Budget -= bets.get(i); + handDone = true; + } + break; + case 2: // Stand + handDone = true; + break; + case 3: // Double Down + if (bets.get(i) * 2 <= Budget) { + bets.set(i, bets.get(i) * 2); + playerHands.set(i, playerHands.get(i) + + getCardWithAceHandling(playerHands.get(i), playerAceCounts.get(i))); + if (playerHands.get(i) > 21) { + System.out.println("You busted!"); + Budget -= bets.get(i); + } + handDone = true; + } else { + System.out.println("Not enough budget to double down."); + } + break; + case 4: // Split + if (playerHands.size() < 4 && bets.get(i) * 2 <= Budget) { + int firstCard = playerHands.get(i) / 2; // Assuming the player has exactly two of the + // same card value + int secondCard = playerHands.get(i) - firstCard; + + if (firstCard == secondCard) { + playerHands.set(i, firstCard + getCard()); + playerHands.add(secondCard + getCard()); + playerAceCounts.add(0); + bets.add(bets.get(i)); + Budget -= bets.get(i); // Deduct the additional bet for the split + } else { + System.out.println("Cannot split non-matching cards."); + } + } else { + System.out.println("Cannot split more hands or not enough budget."); + } + break; + default: + System.out.println("Invalid choice."); + break; + } + } + } + + // Dealer's turn + int dealerHand = getCard(); + dealerHand += getCard(); + while (dealerHand < 17) { + dealerHand += getCardWithAceHandling(dealerHand, 0); + } + dealerDone = true; + + // Determine winner + for (int i = 0; i < playerHands.size(); i++) { + if (playerHands.get(i) <= 21 && dealerHand <= 21) { + if (playerHands.get(i) > dealerHand) { + System.out.println("Hand " + (i + 1) + " wins!"); + Budget += bets.get(i); + } else if (playerHands.get(i) < dealerHand) { + System.out.println("Hand " + (i + 1) + " loses."); + Budget -= bets.get(i); + } else { + System.out.println("Hand " + (i + 1) + " ties."); + } + } else if (dealerHand > 21) { + System.out.println("Dealer busted! Hand " + (i + 1) + " wins!"); + Budget += bets.get(i); + } else if (playerHands.get(i) > 21) { + System.out.println("Hand " + (i + 1) + " busted."); + Budget -= bets.get(i); + } + } + + turnCount++; + printBudget(); + } + } + + public static void shuffleCards() { + for (int x = 0; x < 4; x++) { + for (int y = 0; y < 13; y++) { + card[x][y] = true; + } + } + System.out.println("Cards shuffling..."); + } + + public static int getCard() { + Random random = new Random(); + int cardValue = 0; + + do { + int number = random.nextInt(13); + int symbol = random.nextInt(4); + + if (card[symbol][number]) { + card[symbol][number] = false; + printCard(number, symbol); + + if (number == 0) { // Ace + return 11; + } else if (number >= 10) { // Jack, Queen, King + return 10; + } else { // Number cards (2-10) + return number + 1; + } + } + } while (true); + } + + public static int getCardWithAceHandling(int currentHand, int aceCount) { + int cardValue = getCard(); + currentHand += cardValue; + + if (cardValue == 11) { + aceCount++; + } + + while (currentHand > 21 && aceCount > 0) { + currentHand -= 10; + aceCount--; + } + + return currentHand; + } + + public static void printCard(int card, int symbol) { + String displayNumber; + char displaySymbol; + switch (symbol) { + case 0: + displaySymbol = '\u2665'; // Hearts + break; + case 1: + displaySymbol = '\u2666'; // Diamonds + break; + case 2: + displaySymbol = '\u2663'; // Clubs + break; + case 3: + displaySymbol = '\u2660'; // Spades + break; + default: + System.out.println("Error"); + displaySymbol = 0; + break; + } + + switch (card) { + case 0: + displayNumber = "A"; + break; + case 10: + displayNumber = "J"; + break; + case 11: + displayNumber = "Q"; + break; + case 12: + displayNumber = "K"; + break; + default: + displayNumber = String.valueOf(card + 1); + break; + } + System.out.println("----"); + System.out.println("|" + displaySymbol + displayNumber + "|"); + System.out.println("----"); } public static void playRoulette() { - // Placeholder for Roulette game logic System.out.println("Roulette game coming soon..."); - // Update budget here based on game result printBudget(); } public static void printBudget() { System.out.println("Current Budget: $" + Budget); } + + public static int enterBet() { + while (true) { + int bet = getInput("Enter your bet: "); + if (bet <= Budget) { + return bet; + } else { + System.out.println("You don't have enough money."); + } + } + } } diff --git a/Code/gambling/src/Gambling.pap b/Code/gambling/src/Gambling.pap new file mode 100644 index 0000000..b48b2f2 --- /dev/null +++ b/Code/gambling/src/Gambling.pap @@ -0,0 +1,346 @@ + + + + + + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ budget]]> +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + +
+ + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + +
+
+
+ \ No newline at end of file