Results 1 to 3 of 3

Thread: Quick $10

  1. #1
    aksharshah is offline Member
    Join Date
    Jun 2016
    Posts
    2
    Rep Power
    0

    Default Quick $10

    I'm sorry for this I am, but I need someone to do this for me, I am willing to pay, for some of you it'll probablly be really easy.
    Actually scratch that, most of you would find this like child's play. So I took computer science this year as a junior, I have this project due on the 3rd. This will be my final grade, and our teacher has taught us nothing, he spent the whole year teaching python and he is really arrogant and he thinks programs like AppInventor and Alice should've prepared us for this. He spent the last 3 weeks of school teaching us Java and we waited all year for it. I honestly hate his guts.
    I am willing to pay a small price of $10 to anyone who can do this for me.
    Okay so my final project is a card game.
    He has given us a small outline but I haven't learned any of this and cannot do it, also I am boggled down in other homework and finals, I'm a junior in High School.
    I would really appreciate this and trust me I'm not that one slacker kid, I know that I can eventually do this myself, but it would be extremely overwhelming with no background, and he hardly taught us enough of the language Python to make a calculator. I don't think it would help this. I could learn this by myself if I had the ambition, but I don't anymore and I need to pass my other finals which are next week, my teachers didn't start reviewing till yesterday; Tuesday.

    Now that I filled you in lets do this.

    The simpler the code the better but you have to use his outline:

    HIS OUTLINE:

    Create a new java project for the card game.
    Create the appropriately named package for the java project.
    Create two object classes: Card, Deck and a driver class, Main.


    Add the shuffle method to the deck class.

    Java Code:
    Create a new java project for the card game.
    Create the appropriately named package for the java project.
    Create two object classes: Card, Deck and a driver class, Main.
    
    
    Add the shuffle method to the deck class.
    
    public void shuffle(){
    	//initialize two integer variables, not assigned, to hold random numbers.
    //Initialize a card, call it “temp”  
    
    //initialize a for loop that will start at zero and continue until it reaches the length of cardArray, incrementing by one each time.
    		//Set each of those random number holders equal to 
    			(int)(Math.random()*cardArray.length);
    		//Set temp equal to the index of cardArray at the first random number
    //Set the index of cardArray at the first number equal to the second
    //Set the index of cardArray at the second number equal to temp
    	}
    }
    
    
    Initialize a new integer named nextToDeal at the top of the class and set equal to 0.
    Add this method to the Deck class:
    
    public Card deal(){
    		nextToDeal++;
    		return cardArray[nextToDeal - 1];
    	}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Create a new class:
    
    public class Hand {
    	//initialize a new cardArray with 5 elements.
    	//Initialize a variable to hold the number of cards and set equal to 0.
    	//Create a constructor for the class that takes in two Card inputs, c1 and c2.
    	//Set the first and second indices of the cardArray to the two inputs. 
    	//Change the value of the variable that holds the number of cards to be the correct number of cards.
    		
    	//Create a method to get points.
    		//initialize a variable for the points and set equal to zero.
    		//run a for loop that starts at zero and increments by 1 until it reaches the variable for the number of cards you created at the top.
    			//add to the points variable for each value in the cardArray[i].points.  
    	Using index “i” will iterate through the list while in the for loop.
    			//If the number of points is over 21, reset back to zero.
    			points += cardArray[i].points;
    		}//Close the inside for loop
    			}//close the if statement for points over 21.
    		return points;
    	} //close the method
    
    
    
    Copy and paste this code under the getPoints() method.  Make sure you understand it!
    
    
    	public void display(){
    		for(int i = 0; i < numCards; i++)
    			System.out.println(cardArray[i]);
    	}
    
    	public void hit(Card c){
    		if(numCards >= 5){System.out.println("Maximum number of cards is 5.");
    		return;
    		}
    		cardArray[numCards] = c;
    		numCards++;
    	}
    }
    
    
    
    
    
    
    
    Edit the main method to include the following:
    
    public static void main(String args[]){ 
    		Scanner reader = new Scanner(System.in);
    		//Initialize a new Deck called deck.
    		//Shuffle the deck.
    		Hand dealer = new Hand(deck.deal(),deck.deal());
    		Hand player = new Hand(deck.deal(),deck.deal());
    		//initialize two variables, playerPoints and dealerPoints, one to hold each player’s total.
    		//Print out the string, “Here is your hand.”
    		player.display();
    //Set playerPoints equal to the getPoints method on the player hand.
    	System.out.println("You have " + playerPoints + " points.");
    
    		int choice = 1;
    		while(choice == 1 && playerPoints < 21 && player.numCards < 5){
    			//Print out a statement asking the user if they want another card, 1 for yes and two for no.
    			//Set a variable choice equal to the next integer from the reader.
    			//Conditional statement if the choice is 1{
    				//call the hit function on the player referencing deck.deal()
    				//Print out the phrase “Here is your hand.”
    				//call the display function on player
    				//set playerPoints equal to the getPoints() function on player
    				System.out.println("You have " + playerPoints + " points.");
    			}
    		 }
    		//set dealerPoints equal to the getPoints() method on dealer hand. 
    		//Run a while loop, while the dealerPoints is less than 16 and the dealer.numCards is less than 5.
    			//Call the hit function on the dealer referencing deck.deal()
    			//again, set dealerPoints equal to the getPoints() method on the dealer hand.
    		}//Close the while loop
    		System.out.println("Dealer has:");
    		dealer.display();
    		//Print out a statement that tells the user how many points the dealer has.
    
    		//Write a series of if/else if statements to print out each of the possible outcomes of the game.  There should be 5 cases.
    Also given this code earlier and instruction earlier:

    Part II: CARD GAME

    Using the Card constructor below, implement a Deck Object as described below. Test that the program works as described. When finished, add the following features:

    A. Add a method shuffle to the Deck Class. Call the method from the Main class to verify that the deck is indeed shuffled.

    B. Add a Hand Class that contains an array of 5 Card references. Have the program Deal the Hand two cards and display them for the user. Tell the user how many points they have and ask them if they would like another card or not. Continue to allow the player to add cards until they reach 5 cards or the total is greater than 21.

    C. Adjust the Card class to allow Aces to count as 11 to start. If the Hand Class has a value greater than 21, have the Hand Class check for Aces and reduce their point value to 1.

    D. Have the program create a dealer Hand that the user can play against. The user should try to get as close to 21 without going over in an effort to beat the Dealer. If the Dealer has 16 or more the Dealer should stop taking cards.

    Here is the code to get you started:

    Java Code:
    public class Main {
    public static void main(String args[]){ Deck d = new Deck(); d.print();
    }
    }
    
    public class Deck {
    Card[] cardArray = newCard[52];
    Deck(){ //constructor
    int suits = 4;
    int cardType = 13;
    int cardCount = 0;
    for(int i = 1; i <= suits; i++)
    for(int j = 1; j <= cardType; j++){
    cardArray[cardCount] = new Card(i,j);
    cardCount++;
    }
    }
    public void print(){
    for(int i = 0; i < cardArray.length; i++)
    System.out.println(cardArray[i]);
    }
    }
    public class Card{
    String suit,name;
    int points; Card(int n1, int n2){
    suit = getSuit(n1);
    name = getName(n2);
    points = getPoints(name);
    }
    public String toString(){
    return "The " + name + " of " + suit;
    }
    public String getName(int i){ 
    if(i == 1)	return "Ace"; 
    if(i == 2)	return "Two"; 
    if(i == 3)	return "Three";
    if(i == 4)	return "Four"; 
    if(i == 5)	return "Five"; 
    if(i == 6)	return "Six"; 
    if(i == 7)	return "Seven";
    if(i == 8)	return "Eight";
    if(i == 9)	return "Nine"; 
    if(i == 10)		return "Ten"; 
    if(i == 11)		return "Jack";
    if(i == 12)		return "Queen";
    if(i == 13)		return "King";
    return "error";
    }
    public int getPoints(String n){
    if(n == "Jack" ||n == "Queen" ||n == "King"||n == "Ten")
    return 10;
    if(n == "Two")
    return 2;
    if(n == "Three")
    return 3;
    if(n == "Four")
    return 4;
    if(n == "Five")
    return 5;
    if(n == "Six")
    return 6;
    if(n=="Seven") 
    return 7;
    if(n == "Eight")
    return 8;
    if(n == "Nine")
    return 9;
    if(n == "Ace")
    return 1;
    return -1;
    }
    public String getSuit(int i){
    if(i == 1)	return "Diamonds"; 
    if(i == 2)	return "Clubs"; 
    if(i == 3)	return "Spades"; 
    if(i == 4)	return "Hearts"; 
    return "error";
    }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Quick $10

    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Quick $10

    Thread closed again; we don't want cheaters here.

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Need some quick help
    By Durfsurn in forum Forum Lobby
    Replies: 1
    Last Post: 10-19-2013, 01:50 PM
  2. Quick Help!!
    By MrA in forum New To Java
    Replies: 1
    Last Post: 11-10-2010, 07:38 PM
  3. Quick help
    By locazor in forum New To Java
    Replies: 15
    Last Post: 10-17-2010, 07:07 PM
  4. Quick help
    By Qwertypoiuy in forum New To Java
    Replies: 5
    Last Post: 01-06-2010, 10:49 PM

Posting Permissions

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