1 Replies - 774 Views - Last Post: 01 June 2016 - 09:07 PM Rate Topic: -----

#1 aksharshah   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-June 16

Java project, need help, really easy, teacher didn't teach us anyt

Posted 01 June 2016 - 09:01 PM

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 in bitcoin, I prefer not to.
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.

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:

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";
}
}





Is This A Good Question/Topic? 0
  • +

Replies To: Java project, need help, really easy, teacher didn't teach us anyt

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Java project, need help, really easy, teacher didn't teach us anyt

Posted 01 June 2016 - 09:07 PM

The rules clearly state we won't do your homework for you. If you aren't interested in doing the work, we aren't interested in helping. Keep in mind that we expect you to be pulling the horse, so to speak. We are here to offer debugging advice, not walk you through the project.

Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1