From cd811591622e5024f7923337ba83b2aac9a92ed2 Mon Sep 17 00:00:00 2001 From: Sage The DM Date: Tue, 13 Aug 2024 11:39:12 +0200 Subject: [PATCH] 13.8.2024 - Steiner Preparation --- Code/Age/.vscode/settings.json | 7 + Code/Age/README.md | 18 ++ Code/Age/bin/App.class | Bin 0 -> 1838 bytes Code/Age/src/App.class | Bin 0 -> 1489 bytes Code/Age/src/App.java | 30 +++ Code/codinGame/.vscode/settings.json | 7 + Code/codinGame/README.md | 18 ++ Code/codinGame/src/App.java | 5 + Code/gambling/bin/App.class | Bin 2461 -> 7768 bytes Code/gambling/bin/Gambling.pap | 346 +++++++++++++++++++++++++++ Code/gambling/src/App.java | 291 +++++++++++++++++++--- Code/gambling/src/Gambling.pap | 346 +++++++++++++++++++++++++++ 12 files changed, 1041 insertions(+), 27 deletions(-) create mode 100644 Code/Age/.vscode/settings.json create mode 100644 Code/Age/README.md create mode 100644 Code/Age/bin/App.class create mode 100644 Code/Age/src/App.class create mode 100644 Code/Age/src/App.java create mode 100644 Code/codinGame/.vscode/settings.json create mode 100644 Code/codinGame/README.md create mode 100644 Code/codinGame/src/App.java create mode 100644 Code/gambling/bin/Gambling.pap create mode 100644 Code/gambling/src/Gambling.pap 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 0000000000000000000000000000000000000000..73a4dc0861a1a781e783203025fcbc0a660b4df3 GIT binary patch literal 1838 zcmaJ>ZBr9h7(F-1=8YIIfJQ~TwkQOtv8}d1l!^fg7?c`{TKjfcZpq5Bo5^kzenEeN zold{|#V>U_+MzT30sTqsjP1F*sf2-PW^!Nlc{|U!=iWcx?EL}Y22=_$f%r_bnLCW40T3m7$)sxZyAv|WJ{qmOF)CF?=Ub~h`!Om=R^Qq92jTt9_^ zK>xniTT2=PgtsDF$_=t$vK&sLD3IP%!J^x26a3)l5$PAxI87wghV5)*Fobg{oITKb zeb*1vb`I~rWZPbtD9U4duIG@eBYRm(-sCyzUxEMe9Nx!efs@;E zOI1DBlEHmDXmI5R(hbP};OK1WFeL@DH(o#t<2)JJ+N5Lu5eFlXVG|MI0%Dd_b06}^ z?T)~)dLXT>W!Vf5J%veuqay=F0txg6#-xkgB?uC$QDB9=(Et9B?JN{4b^ z)LPybUPqp!$Y&>{D6)0;MrCK~Ub|(fd0StFG}V4tXP~}rd0yZLE!kXFLBredv$%)V z6zT%Q`!#I$iMOT7QK{$z=cN^RtzF&a7Xm+aciHid5-v!0!%_Zl&GWX}&B|fmU0)6a zuI@I~5$@drh#rGVw{$uwD1N7I2ddJW#OG-|AT3=&4{yPgDbn~-V4%wo-GI>Y74^E> zkb(Ksb{unEnYL>Rb63fhpT;)~n{xxz>b^pPamX!dF;yMu`-*P_8NP6c#-oTy!4f$4 z|E_#iA{KF;HzTgE7f0#^NscM*%A5sfW9&83zi<&lmZLUn*B*|!$bs`Q?lQ=umtK8b zCuljY(+HhVr)%aH@=JyO-!S;YLgAF2mR{ma;ruJSm!CAA=9dMT{QM^CEPqmU(x8bCXJ$zfA;e~ziPzs5b-oou?-?i5?7kY zGki*VaGI!1V!lHAHKLv(;(1!`p&#F30PD1Sd~bE9V~k`E_y8Yrj={x8xXKzn0k%r8v7dC!;Efa z_R=eS_985!3D46T1lxl%%rO+gIT6LP;BDG^2)u@6W{=}e7R%kpu)zQT literal 0 HcmV?d00001 diff --git a/Code/Age/src/App.class b/Code/Age/src/App.class new file mode 100644 index 0000000000000000000000000000000000000000..7b02030d7e45247abf14866b189ed4a264cc3b2e GIT binary patch literal 1489 zcmaJ>-%}e^6#i~D$%e3mHjq+li?Px|XeC;;MS|5fKmh|q)2ZY5bXl%s%Vsx|y{YBh znf?hn`sz$ye6bJIp)>vgzWU$vq4m3)2w}*$5BHvX?)mYZ@0`7Vzdrm6z%6{8#TiUy z@J<$^C=TIWT+ZOVET(WJPlHk(0wo*Q%+2*IhVXtK36zb&2j=*pjT<&T5=bw4fv0Z^ zSTm)E0?BH)qXb54UZ6HR&280wAh&&Ll1=Fa0_SGFt38sBW!aa(Zn>`8Ua(s+jw5v~ z-MtOj>e*+PpSY@}y)cMud@PXJReCLGb+kZXWOSzR&b9@5<24^({z9Pk#br1*sn#2>AJ4;|ab0!i>-Oa-dbazgL3saCOkA41$x2t0xPA zdcrv)*_`J!8|$V!n*vkE)O*3>a8LDSw_EdybamL?x3R@RtA*iShYfVrOslKDj3PxM ze(s0Ti_x8!RT=E~Dw^s#R!+m~)0}X8u-{Sx%=`ba?&wtdThI%^$@lA?Ruvmx30yf< z-ym!PlmBnW*J6|pi}@_RApG;Vj`4JfyWpOheF5*;EDTYrvZK6QY!bu(2+{ffEiLh7ko`so);@}_hM8{jSF=|f~<`5A_O zOo?Z2{xLZdan2iXD5rQzGgAh`%%10Z0VBAK9Ims3c^0um`1h#Wpw|RF99XY$$+AT0 z6}`_>lO+1L=*=gElEJ>nvJ>1dzQoYC&yjtB;Tqx09-5p77`b+U-0!^aR-dCa7<-t} kCK$=WMV=ERYlC~1R$t;iYP`A1^EmIPshf${*?67%7t$qZJpcdz literal 0 HcmV?d00001 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 22c5ba3e48f2eff44d9c9a0bb5e56ff261f36540..f6992885263ea8c8b6acd5ce8a5be2a0c442f19f 100644 GIT binary patch literal 7768 zcmbtZdtg-6ng5-+Gnt!VfMj5Jgn$=>kc1FOfK(HRLJ*C-l%RlYYi?$4$jD@FoCh(M zuG->SS68iFt&i4<*iBcdwrC+jvDRH5t<|lrcCD?hZCAVQ+U-NzwTfnc-?=x*WMy~% z*nydI?z!Lj&iDL%-@W<4M@Jt8uu9d35l}Ez_w|JlR4BW|-eWIG+nHTUHg{d(B=QO+ zYYNF-4kxNzA(*hUNz(7!d67bCzL3qdxrGdGmTqj{bn(^;wruK9nAqlKa(O$GztBz> z9E0Z=La=(fM<5Fk1#@L0oyw&0tz=hSb0K-Rxk;xK3R9v8p(G4bE~Z7{&t^nXiV}s% z8&Vl(Q=zxZ$!@i~(vCuGgPX9^7uwmBT>Fb9D>e5B49t#V7Rq=+z9*Ga2yLLcExhct zQyHF6y>r8u+8z09DzmGl=E4XMKQ)T^vT>rYO4;eu<<1%>Uy3SJhp}*+xjF`Nd8apu z8q`uDw?Lc3J+>)#$$8|NCuhg*Z81@&P}NXxwYjNGcRJNqXEoMaYtnXN_a*$+SO?VHc=^hVQY_L?Q-q3mC6Y2}FG>m;1i9$6l63t6i>mCfa?e81}*Ku%i~CM>VFHuvRIOiL=xRI9WsYq51sD&K6a z&D#AGYfLC^+0Mw<6f|=t*=((MoIa0zqL9tfYgP}}Nk|Y_sR`G*1!kVL*6q)brFWs_ z5lKa9PfW*hGmh0Oa*O`t@Mj8}y`%clB2Ig^97O(mX#No`EVtXDeXN{KmoiuiPMwt# zdRgtY82zp$7O8S%`YDCgD?HaG9Xm~H_ovcnD=Dgab|+?~(z1KNJIc;mX~(AJ8a`q5 zF)#DNrc+^Y6Z2GiN^_u(vrew3(A}MOl9t^qDYa~I!%|C-P_}f@*k`+L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EJ>?aHMzJLZUf79stSD$a|-J`5%%W>ayr;Cx^n&0b5H8{T%cL)9IqN= zR8qe%@JJ=KC5&~a@tXV)v+AV1G(>Tb{6?Z?mqwIv;mc~x33Mz8^z2rQxonjsYoN^T zF{_^EW-<(;$Ut{WXFrX0j)*4)mQfNoT((x_l;;+#;GrFqxT*%08?cx<8QS|bFOZsJ zDhqPPRzpB%Q)d)-IDTw*&0Ce(sNth~XRJct z`RfW$Md17TMvJv0hqp+VBdfi6&s(ik#@@$PCwa$ke!U|1QLk^7Xey4?2OPVYvK(j5 z4&+#C6C52RrhTgB`|Lt9O5~{7E7;;W)jd;=RjtaZhBbjR?*+YI7#f}l9RGh+W{*w|Sp}c;q!k7GL1%ON`%9 zcs}05jloTP@(a%*1`mc|^bpH&-hE=1mKLsV;uiIq)v%BJiau&5DXZ1_eU04WOWesT z|M}SeME47%euAN7_sGF>wRjL8UOSuI#BAd6NTR1R@dLW3+WnYmRXU$3!qA~a#aQ$( zWPfpE`$t|J(Re$|*J*<8CFnk8Aq|scrU^BRL0n*tu9DOV?q*1Ap5)DwzAs7LH@M7> z9Dzp-pOh(zhZ$50R^os=utd$T7_y03d`+?&=;<;on|S{WKXH$_N>BoHBJma-8b&na z-taU178xO0$r-0VzsKRSj-^=|x6!!NpP3@cX zaI4M(hjZ-VQjDRM7|87_NPvF!V5CBYJ1oWgu7gI{1kylWR{2)0zUAX1;7*PI8lGYu GNB;$%NEF@x 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