Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By gimbal2

Thread: My name is Jesse.

  1. #1
    JesseJson is offline Member
    Join Date
    Aug 2013
    Location
    AZ
    Posts
    2
    Rep Power
    0

    Default My name is Jesse.

    Hey everyone,

    I have been signed up with this forum for a little while now and have read over a lot of posts but never have posted anything.
    I'm a beginner who has been trying to learn java on my own on and off (Unsuccessfully) really since Android came out. I finally bit the bullet and am now in Java level 1 at my community college. I have been intrigued with computer programming since Counter-Strike 1.6. I started trying to learn Pawn and could only play around with other people's work by cutting and pasting and moving things around and seeing what worked and what did not. It was cool but with no real structure of learning for me I never kept on with it. I have learned quite a bit so far and hope to keep learning more and more. We have only been coding inside the main method because we are beginners. ( next week we start writing our own classes! YES! )

    We had an assignment to print out a random suit and card in a sentence and this made me want to make blackjack.
    So as the semester has progressed I have added more and more too it and after messing with loops for hours i finally got it! This is the first program I have written with no help from the internet and just from what I have learned.(our teacher did give us psuedocode for the card assignment so that was my starting point) I had to cheat and use ctrl+shift+f to format my code inside eclipse because i got lost in brackets quite a few times
    I'm sure some people will look at this and it will make their eyes hurt but i'm a beginner and got everything working how I want it(so far).
    now that i finally got this working I would like to share it:

    PHP Code:
    package ch4;
    
    import java.util.Random;
    import java.util.Scanner;
    import java.text.NumberFormat;
    
    public class BlackJack 
    {
    
    	public static void main(String[] args)
    	{
    
    		final int ACE_LOW = 1, ACE_HIGH = 11;
    
    		int randSuitA, randSuitB, randSuitC, randCardA = 0, randCardB = 0, randCardC = 0, cardTotalA = 0, cardTotalB = 0, 
    			cardTotalC = 0, cardTotal, ace, gameOn = 0, hitOrStay = 0, randDealerA, randDealerB, randDealerC, dealerTotal = 0, 
    			dealerTotalA = 0, dealerTotalB = 0, dealerTotalC = 0;
    
    		double cashTotal = 0, betTotal = 0;
    
    		String card = "", suit = "", dealerCard = "", dealerSuit = "";
    
    		Random rand = new Random();
    		Scanner scan = new Scanner(System.in);
    		NumberFormat fmt = NumberFormat.getCurrencyInstance();
    
    		System.out
    				.print("Would you like to play BlackJack (1 = YES  2 = NO)? ");
    		gameOn = scan.nextInt();
    
    		System.out.print("How much would you like to buy in with? ");
    		cashTotal = scan.nextDouble();
    
    		System.out.println();
    
    		while (gameOn != 2)// our game loop. if it equals 2 the game is over
    		{
    			System.out
    					.println("\n-----------------NEW-----GAME-----------------------");
    			
    			System.out.println("Total Cash: " + fmt.format(cashTotal));
    
    //******************************DEALERS FIRST CARD****************************************************************
    			
    			while (betTotal > cashTotal || betTotal == 0)
    			{
    				System.out.print("Enter your Bet: ");
    				betTotal = scan.nextDouble();
    			}
    
    			randSuitA = 1 + rand.nextInt(4);
    			switch (randSuitA)
    			{
    				case 1:
    					dealerSuit = "|   Spades  |";
    					break;
    				case 2:
    					dealerSuit = "|  Hearts   |";
    					break;
    				case 3:
    					dealerSuit = "| Diamonds  |";
    					break;
    				case 4:
    					dealerSuit = "|   Clubs   |";
    					break;
    			}
    
    			randDealerA = 1 + rand.nextInt(12);
    			switch (randDealerA)
    			{
    				case 1:
    					dealerCard = "|  A Ace A  |";
    					break;
    				case 2:
    					dealerCard = "|  2 Two 2  |";
    					break;
    				case 3:
    					dealerCard = "| 3 Three 3 |";
    					break;
    				case 4:
    					dealerCard = "| 4 Four 4  |";
    					break;
    				case 5:
    					dealerCard = "| 5 Five 5  |";
    					break;
    				case 6:
    					dealerCard = "|  6 Six 6  |";
    					break;
    				case 7:
    					dealerCard = "| 7 Seven 7 |";
    					break;
    				case 8:
    					dealerCard = "| 8 Eight 8 |";
    					break;
    				case 9:
    					dealerCard = "| 9 Nine 9  |";
    					break;
    				case 10:
    					dealerCard = "| 10 Ten 10 |";
    					break;
    				case 11:
    					dealerCard = "| J Jack J  |";
    					break;
    				case 12:
    					dealerCard = "| Q Queen Q |";
    					break;
    				case 13:
    					dealerCard = "| K King K  |";
    					break;
    			}
    
    			if (randDealerA == ACE_LOW)
    			{
    				dealerTotalA = ACE_HIGH;
    			}
    			else
    				if (randDealerA == 2)
    				{
    					dealerTotalA = 2;
    				}
    				else
    					if (randDealerA == 3)
    					{
    						dealerTotalA = 3;
    					}
    					else
    						if (randDealerA == 4)
    						{
    							dealerTotalA = 4;
    						}
    						else
    							if (randDealerA == 5)
    							{
    								dealerTotalA = 5;
    							}
    							else
    								if (randDealerA == 6)
    								{
    									dealerTotalA = 6;
    								}
    								else
    									if (randDealerA == 7)
    									{
    										dealerTotalA = 7;
    									}
    									else
    										if (randDealerA == 8)
    										{
    											dealerTotalA = 8;
    										}
    										else
    											if (randDealerA == 9)
    											{
    												dealerTotalA = 9;
    											}
    											else
    												if (randDealerA >= 10)
    												{
    													dealerTotalA = 10;
    												}
    
    			System.out.println("Dealer drew a: \n" + "\t\t\t_____________\n"
    					+ "\t\t\t|           |\n\t\t\t" + dealerCard
    					+ "\n\t\t\t|           |" + "\n\t\t\t|    of     |\n"
    					+ "\t\t\t|           |\n\t\t\t" + dealerSuit
    					+ "\n\t\t\t|___________|" + "\n");
    
    //********************************************USERS FIRST CARD**************************************************************
    
    			randSuitA = 1 + rand.nextInt(4);
    			switch (randSuitA)
    			{
    				case 1:
    					suit = "|   Spades  |";
    					break;
    				case 2:
    					suit = "|  Hearts   |";
    					break;
    				case 3:
    					suit = "| Diamonds  |";
    					break;
    				case 4:
    					suit = "|   Clubs   |";
    					break;
    			}
    
    			randCardA = 1 + rand.nextInt(12);
    			switch (randCardA)
    			{
    				case 1:
    					card = "|  A Ace A  |";
    					break;
    				case 2:
    					card = "|  2 Two 2  |";
    					break;
    				case 3:
    					card = "| 3 Three 3 |";
    					break;
    				case 4:
    					card = "| 4 Four 4  |";
    					break;
    				case 5:
    					card = "| 5 Five 5  |";
    					break;
    				case 6:
    					card = "|  6 Six 6  |";
    					break;
    				case 7:
    					card = "| 7 Seven 7 |";
    					break;
    				case 8:
    					card = "| 8 Eight 8 |";
    					break;
    				case 9:
    					card = "| 9 Nine 9  |";
    					break;
    				case 10:
    					card = "| 10 Ten 10 |";
    					break;
    				case 11:
    					card = "| J Jack J  |";
    					break;
    				case 12:
    					card = "| Q Queen Q |";
    					break;
    				case 13:
    					card = "| K King K  |";
    					break;
    			}
    
    			System.out.println("You drew a: \n" + "\t\t\t_____________\n"
    					+ "\t\t\t|           |\n\t\t\t" + card
    					+ "\n\t\t\t|           |" + "\n\t\t\t|    of     |\n"
    					+ "\t\t\t|           |\n\t\t\t" + suit
    					+ "\n\t\t\t|___________|" + "\n");
    
    //**********************************USERS SECOND CARD***************************************************************************
    
    			randSuitB = 1 + rand.nextInt(4);
    			switch (randSuitB)
    			{
    				case 1:
    					suit = "|   Spades  |";
    					break;
    				case 2:
    					suit = "|  Hearts   |";
    					break;
    				case 3:
    					suit = "| Diamonds  |";
    					break;
    				case 4:
    					suit = "|   Clubs   |";
    					break;
    			}
    
    			randCardB = 1 + rand.nextInt(12);
    			switch (randCardB)
    			{
    				case 1:
    					card = "|  A Ace A  |";
    					break;
    				case 2:
    					card = "|  2 Two 2  |";
    					break;
    				case 3:
    					card = "| 3 Three 3 |";
    					break;
    				case 4:
    					card = "| 4 Four 4  |";
    					break;
    				case 5:
    					card = "| 5 Five 5  |";
    					break;
    				case 6:
    					card = "|  6 Six 6  |";
    					break;
    				case 7:
    					card = "| 7 Seven 7 |";
    					break;
    				case 8:
    					card = "| 8 Eight 8 |";
    					break;
    				case 9:
    					card = "| 9 Nine 9  |";
    					break;
    				case 10:
    					card = "| 10 Ten 10 |";
    					break;
    				case 11:
    					card = "| J Jack J  |";
    					break;
    				case 12:
    					card = "| Q Queen Q |";
    					break;
    				case 13:
    					card = "| K King K  |";
    					break;
    			}
    
    			System.out.println("\t\t\t     and\n" + "\t\t\t_____________\n"
    					+ "\t\t\t|           |\n\t\t\t" + card
    					+ "\n\t\t\t|           |" + "\n\t\t\t|    of     |\n"
    					+ "\t\t\t|           |\n\t\t\t" + suit
    					+ "\n\t\t\t|___________|" + "\n");
    
    			if (randCardA == ACE_LOW)
    			{
    				System.out
    						.print("How would you like to use this ace? Enter 1 or 11: ");
    				ace = scan.nextInt();
    
    				while (ace != ACE_LOW && ace != ACE_HIGH)
    				{
    					System.out.print("Invalid. Please enter a 1 or 11: ");
    					ace = scan.nextInt();
    				}
    
    				if (ace == ACE_LOW)
    				{
    					cardTotalA = ACE_LOW;
    				}
    				else
    					if (ace == ACE_HIGH)
    					{
    						cardTotalA = ACE_HIGH;
    					}
    			}
    			else
    				if (randCardA == 2)
    				{
    					cardTotalA = 2;
    				}
    				else
    					if (randCardA == 3)
    					{
    						cardTotalA = 3;
    					}
    					else
    						if (randCardA == 4)
    						{
    							cardTotalA = 4;
    						}
    						else
    							if (randCardA == 5)
    							{
    								cardTotalA = 5;
    							}
    							else
    								if (randCardA == 6)
    								{
    									cardTotalA = 6;
    								}
    								else
    									if (randCardA == 7)
    									{
    										cardTotalA = 7;
    									}
    									else
    										if (randCardA == 8)
    										{
    											cardTotalA = 8;
    										}
    										else
    											if (randCardA == 9)
    											{
    												cardTotalA = 9;
    											}
    											else
    												if (randCardA >= 10)
    												{
    													cardTotalA = 10;
    												}
    
    			if (randCardB == ACE_LOW)
    			{
    				if (cardTotalA == 10)
    				{
    					cardTotalB = ACE_HIGH;
    				}
    
    				System.out
    						.print("How would you like to use this ace? Enter 1 or 11: ");
    				ace = scan.nextInt();
    
    				while (ace != ACE_LOW && ace != ACE_HIGH)
    				{
    					System.out.print("Invalid. Please enter a 1 or 11: ");
    					ace = scan.nextInt();
    				}
    
    				if (ace == ACE_LOW)
    				{
    					cardTotalB = ACE_LOW;
    				}
    				else
    					if (ace == ACE_HIGH)
    					{
    						cardTotalB = ACE_HIGH;
    					}
    			}
    			else
    				if (randCardB == 2)
    				{
    					cardTotalB = 2;
    				}
    				else
    					if (randCardB == 3)
    					{
    						cardTotalB = 3;
    					}
    					else
    						if (randCardB == 4)
    						{
    							cardTotalB = 4;
    						}
    						else
    							if (randCardB == 5)
    							{
    								cardTotalB = 5;
    							}
    							else
    								if (randCardB == 6)
    								{
    									cardTotalB = 6;
    								}
    								else
    									if (randCardB == 7)
    									{
    										cardTotalB = 7;
    									}
    									else
    										if (randCardB == 8)
    										{
    											cardTotalB = 8;
    										}
    										else
    											if (randCardB == 9)
    											{
    												cardTotalB = 9;
    											}
    											else
    												if (randCardB >= 10)
    												{
    													cardTotalB = 10;
    												}
    
    			cardTotal = cardTotalA + cardTotalB;
    
    			System.out.println("Card Total: " + cardTotal);
    			System.out.println("Dealer is showing: " + dealerTotalA + "\n");
    
    			/*if (cardTotalA + cardTotalB == 21)
    			{
    				System.out.println("BLACKJACK! Congrats you got 21");
    			}*/
    
    //****************************USERS HIT CARDS******************************************************************************
    
    			do // do...while loop for Hit or Stay
    			{
    				if (cardTotal < 21)
    				{
    					System.out.print("HIT or STAY. 1 = HIT | 2 = STAY: ");
    					hitOrStay = scan.nextInt();
    
    					while (hitOrStay != 1 && hitOrStay != 2) // error check
    																// while loop
    					{
    						System.out.print("HIT or STAY. 1 = HIT | 2 = STAY: ");
    						hitOrStay = scan.nextInt();
    					}// end error check
    
    					if (hitOrStay == 1)
    					{
    						randSuitC = 1 + rand.nextInt(4);
    						switch (randSuitC)
    						{
    							case 1:
    								suit = "|   Spades  |";
    								break;
    							case 2:
    								suit = "|  Hearts   |";
    								break;
    							case 3:
    								suit = "| Diamonds  |";
    								break;
    							case 4:
    								suit = "|   Clubs   |";
    								break;
    						}
    
    						randCardC = 1 + rand.nextInt(12);
    						switch (randCardC)
    						{
    							case 1:
    								card = "|  A Ace A  |";
    								break;
    							case 2:
    								card = "|  2 Two 2  |";
    								break;
    							case 3:
    								card = "| 3 Three 3 |";
    								break;
    							case 4:
    								card = "| 4 Four 4  |";
    								break;
    							case 5:
    								card = "| 5 Five 5  |";
    								break;
    							case 6:
    								card = "|  6 Six 6  |";
    								break;
    							case 7:
    								card = "| 7 Seven 7 |";
    								break;
    							case 8:
    								card = "| 8 Eight 8 |";
    								break;
    							case 9:
    								card = "| 9 Nine 9  |";
    								break;
    							case 10:
    								card = "| 10 Ten 10 |";
    								break;
    							case 11:
    								card = "| J Jack J  |";
    								break;
    							case 12:
    								card = "| Q Queen Q |";
    								break;
    							case 13:
    								card = "| K King K  |";
    								break;
    						}
    
    						System.out.println("You drew a: \n"
    								+ "\t\t\t_____________\n"
    								+ "\t\t\t|           |\n\t\t\t" + card
    								+ "\n\t\t\t|           |"
    								+ "\n\t\t\t|    of     |\n"
    								+ "\t\t\t|           |\n\t\t\t" + suit
    								+ "\n\t\t\t|___________|" + "\n");
    
    						if (randCardC == ACE_LOW)
    						{
    							System.out
    									.print("How would you like to use this ace? Enter 1 or 11: ");
    							ace = scan.nextInt();
    
    							while (ace != ACE_LOW && ace != ACE_HIGH)
    							{
    								System.out
    										.print("Invalid. Please enter a 1 or 11: ");
    								ace = scan.nextInt();
    							}
    
    							if (ace == ACE_LOW)
    							{
    								cardTotalC = ACE_LOW;
    							}
    							else
    								if (ace == ACE_HIGH)
    								{
    									cardTotalC = ACE_HIGH;
    								}
    						}
    						else
    							if (randCardC == 2)
    							{
    								cardTotalC = 2;
    							}
    							else
    								if (randCardC == 3)
    								{
    									cardTotalC = 3;
    								}
    								else
    									if (randCardC == 4)
    									{
    										cardTotalC = 4;
    									}
    									else
    										if (randCardC == 5)
    										{
    											cardTotalC = 5;
    										}
    										else
    											if (randCardC == 6)
    											{
    												cardTotalC = 6;
    											}
    											else
    												if (randCardC == 7)
    												{
    													cardTotalC = 7;
    												}
    												else
    													if (randCardC == 8)
    													{
    														cardTotalC = 8;
    													}
    													else
    														if (randCardC == 9)
    														{
    															cardTotalC = 9;
    														}
    														else
    															if (randCardC >= 10)
    															{
    																cardTotalC = 10;
    															}
    
    						cardTotal += cardTotalC;
    
    						if (cardTotal == 21)
    						{
    							System.out
    									.println("BLACKJACK! Congrats you got 21");
    							hitOrStay = 2;
    							gameOn = 0;
    						}
    
    						else
    						{
    							System.out.println("\nCard Total: " + cardTotal);
    						}
    
    						if (cardTotal > 21)
    						{
    							System.out.println("Sorry, You busted.");
    							hitOrStay = 2;
    							gameOn = 0;
    						}
    					}
    					else
    					{
    						gameOn = 0;
    						hitOrStay = 2;
    					}
    				}
    			}
    			while (hitOrStay == 1);// end do..while loop for hit or stay
    
    // *******************************************DEALERS SECOND CARD***************************************************
    
    			randSuitB = 1 + rand.nextInt(4);
    			switch (randSuitB)
    			{
    				case 1:
    					dealerSuit = "|   Spades  |";
    					break;
    				case 2:
    					dealerSuit = "|  Hearts   |";
    					break;
    				case 3:
    					dealerSuit = "| Diamonds  |";
    					break;
    				case 4:
    					dealerSuit = "|   Clubs   |";
    					break;
    			}
    
    			randDealerB = 1 + rand.nextInt(12);
    			switch (randDealerB)
    			{
    				case 1:
    					dealerCard = "|  A Ace A  |";
    					break;
    				case 2:
    					dealerCard = "|  2 Two 2  |";
    					break;
    				case 3:
    					dealerCard = "| 3 Three 3 |";
    					break;
    				case 4:
    					dealerCard = "| 4 Four 4  |";
    					break;
    				case 5:
    					dealerCard = "| 5 Five 5  |";
    					break;
    				case 6:
    					dealerCard = "|  6 Six 6  |";
    					break;
    				case 7:
    					dealerCard = "| 7 Seven 7 |";
    					break;
    				case 8:
    					dealerCard = "| 8 Eight 8 |";
    					break;
    				case 9:
    					dealerCard = "| 9 Nine 9  |";
    					break;
    				case 10:
    					dealerCard = "| 10 Ten 10 |";
    					break;
    				case 11:
    					dealerCard = "| J Jack J  |";
    					break;
    				case 12:
    					dealerCard = "| Q Queen Q |";
    					break;
    				case 13:
    					dealerCard = "| K King K  |";
    					break;
    			}
    
    			if (randDealerB == ACE_LOW)
    			{
    				if (dealerTotalA <= 10)
    				{
    					dealerTotalB = ACE_HIGH;
    				}
    				else
    				{
    					dealerTotalB = ACE_LOW;
    				}
    			}
    			else
    				if (randDealerB == 2)
    				{
    					dealerTotalB = 2;
    				}
    				else
    					if (randDealerB == 3)
    					{
    						dealerTotalB = 3;
    					}
    					else
    						if (randDealerB == 4)
    						{
    							dealerTotalB = 4;
    						}
    						else
    							if (randDealerB == 5)
    							{
    								dealerTotalB = 5;
    							}
    							else
    								if (randDealerB == 6)
    								{
    									dealerTotalB = 6;
    								}
    								else
    									if (randDealerB == 7)
    									{
    										dealerTotalB = 7;
    									}
    									else
    										if (randDealerB == 8)
    										{
    											dealerTotalB = 8;
    										}
    										else
    											if (randDealerB == 9)
    											{
    												dealerTotalB = 9;
    											}
    											else
    												if (randDealerB >= 10)
    												{
    													dealerTotalB = 10;
    												}
    
    			System.out.println("\nDealer drew a: \n" + "\t\t\t_____________\n"
    					+ "\t\t\t|           |\n\t\t\t" + dealerCard
    					+ "\n\t\t\t|           |" + "\n\t\t\t|    of     |\n"
    					+ "\t\t\t|           |\n\t\t\t" + dealerSuit
    					+ "\n\t\t\t|___________|" + "\n");
    
    			dealerTotal = dealerTotalA + dealerTotalB;
    
    			while (dealerTotal <= 17)
    			{
    
    				randSuitC = 1 + rand.nextInt(4);
    				switch (randSuitC)
    				{
    					case 1:
    						dealerSuit = "|   Spades  |";
    						break;
    					case 2:
    						dealerSuit = "|  Hearts   |";
    						break;
    					case 3:
    						dealerSuit = "| Diamonds  |";
    						break;
    					case 4:
    						dealerSuit = "|   Clubs   |";
    						break;
    				}
    
    				randDealerC = 1 + rand.nextInt(12);
    				switch (randDealerC)
    				{
    					case 1:
    						dealerCard = "|  A Ace A  |";
    						break;
    					case 2:
    						dealerCard = "|  2 Two 2  |";
    						break;
    					case 3:
    						dealerCard = "| 3 Three 3 |";
    						break;
    					case 4:
    						dealerCard = "| 4 Four 4  |";
    						break;
    					case 5:
    						dealerCard = "| 5 Five 5  |";
    						break;
    					case 6:
    						dealerCard = "|  6 Six 6  |";
    						break;
    					case 7:
    						dealerCard = "| 7 Seven 7 |";
    						break;
    					case 8:
    						dealerCard = "| 8 Eight 8 |";
    						break;
    					case 9:
    						dealerCard = "| 9 Nine 9  |";
    						break;
    					case 10:
    						dealerCard = "| 10 Ten 10 |";
    						break;
    					case 11:
    						dealerCard = "| J Jack J  |";
    						break;
    					case 12:
    						dealerCard = "| Q Queen Q |";
    						break;
    					case 13:
    						dealerCard = "| K King K  |";
    						break;
    				}
    
    				if (randDealerC == ACE_LOW)
    				{
    					if (dealerTotal <= 10)
    					{
    						dealerTotalC = ACE_HIGH;
    					}
    					else
    					{
    						dealerTotalC = ACE_LOW;
    					}
    				}
    				else
    					if (randDealerC == 2)
    					{
    						dealerTotalC = 2;
    					}
    					else
    						if (randDealerC == 3)
    						{
    							dealerTotalC = 3;
    						}
    						else
    							if (randDealerC == 4)
    							{
    								dealerTotalC = 4;
    							}
    							else
    								if (randDealerC == 5)
    								{
    									dealerTotalC = 5;
    								}
    								else
    									if (randDealerC == 6)
    									{
    										dealerTotalC = 6;
    									}
    									else
    										if (randDealerC == 7)
    										{
    											dealerTotalC = 7;
    										}
    										else
    											if (randDealerC == 8)
    											{
    												dealerTotalC = 8;
    											}
    											else
    												if (randDealerC == 9)
    												{
    													dealerTotalC = 9;
    												}
    												else
    													if (randDealerC >= 10)
    													{
    														dealerTotalC = 10;
    													}
    
    				System.out.println("Dealer drew a: \n"
    						+ "\t\t\t_____________\n"
    						+ "\t\t\t|           |\n\t\t\t" + dealerCard
    						+ "\n\t\t\t|           |" + "\n\t\t\t|    of     |\n"
    						+ "\t\t\t|           |\n\t\t\t" + dealerSuit
    						+ "\n\t\t\t|___________|" + "\n");
    
    				dealerTotal += dealerTotalC;
    
    			}
    
    			if (dealerTotalA + dealerTotalB == 21)
    			{
    				System.out.println("Dealer got BlackJack: " + dealerTotal);
    			}
    			else
    				if (dealerTotalA + dealerTotalB != 21 && dealerTotal == 21)
    				{
    					System.out.println("Dealer got: " + dealerTotal);
    				}
    				else
    					if (dealerTotal < 21)
    					{
    						System.out.println("Dealer's Total: " + dealerTotal);
    					}
    					else
    					{
    						System.out
    								.println("The Dealer Busted! with a total of: "
    										+ dealerTotal);
    					}
    
    			if (dealerTotal > cardTotal && dealerTotal <= 21
    					|| dealerTotal <= 21 && cardTotal > 21)
    			{
    				cashTotal -= betTotal;
    				System.out.println("Dealer Won... You lost: "
    						+ fmt.format(betTotal) + "\nTotal Cash: "
    						+ fmt.format(cashTotal));
    			}
    			else
    				if (cardTotalA + cardTotalB == 21)
    				{
    					betTotal *= 2.5;
    					cashTotal += betTotal;
    
    					System.out.println("You Got BlackJack! You Win: "
    							+ fmt.format(betTotal) + "\nTotalCash: "
    							+ fmt.format(cashTotal));
    				}
    				else
    					if (dealerTotal < cardTotal && cardTotal <= 21
    							|| dealerTotal > 21 && cardTotal <= 21)
    					{
    						betTotal *= 2;
    						cashTotal += betTotal; // user won so multiply betTotal
    												// by 2 then add it to cashTotal
    
    						System.out.println("You Won " + fmt.format(betTotal)
    								+ ".\nTotal Cash: " + fmt.format(cashTotal));
    					}
    					else
    						if (dealerTotal == cardTotal && dealerTotal <= 21)
    						{
    							System.out
    									.println("Its a Draw, at least you didn't lose! \nTotal Cash: "
    											+ fmt.format(cashTotal));
    						}
    						else
    							if(cardTotal > 21)
    							{
    								cashTotal -= betTotal;
    								System.out.println("You lost: " + fmt.format(betTotal) + "\nTotal Cash: " + fmt.format(cashTotal));
    							}
    
    			gameOn = 0;
    
    			while (gameOn != 1 && gameOn != 2)
    			{
    				System.out.print("\nPlay BlackJack Again? (1= YES  2 = NO)? ");
    				gameOn = scan.nextInt();
    				
    				if(cashTotal == 0) //check to see if user has any money left
    				{
    					System.out.println("You are out of money, how much would you like to buy in with? ");
    					cashTotal = scan.nextDouble();
    				}
    				
    				betTotal = 0;
    			}
    		}
    		System.out.print("You quit BlackJack, Goodbye");
    		scan.close();
    	}
    }
    If there is a way to make all of this code scrollable please let me know.

    Have a Great Day!

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,105
    Rep Power
    6

    Default Re: My name is Jesse.

    Good job! Now I challenge you to cut that long wall of code up into smaller methods. You probably haven't learned about using classes and objects yet, so static methods would be fine.

    Also a little code-readability tip: try to avoid "magic numbers" especially when they repeat a lot. One huge magic number in your code is 21. That has a special meaning and you should label it as such.

    Java Code:
    public class Bla {
      public static final int BLACKJACK = 21;
    
      ...
    
      if (dealerTotalA + dealerTotalB == BLACKJACK) {
        System.out.println("Dealer got BlackJack: " + dealerTotal);
      }
    See?
    Last edited by gimbal2; 02-20-2014 at 08:50 AM.
    JesseJson likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JesseJson is offline Member
    Join Date
    Aug 2013
    Location
    AZ
    Posts
    2
    Rep Power
    0

    Default Re: My name is Jesse.

    Thank you I will try! I need to read up on static methods. Next week I start learning about Classes and Objects!

    Yeah I thought about that at one point. In class we have been doing very small code snippets and have been hard coding everything. I need to get in the habit of using constants.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •