Applets :: Display Images Of Playing Cards And Shuffle The Deck
Jul 28, 2014
"In this assignment you will use an applet to display images of playing cards. The applet should load a deck of 52 playing card images from the "images" folder that you downloaded. The applet should shuffle the deck (use a random number generator) and display the first 10 cards of the shuffled deck. Display the cards in two rows of five cards each."
That is my goal for this assignment. I've got my code compiling and I will post it below and I've got an html page but when I try to open it I get an error
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;
public class Assignment12 extends Applet {
Image card1;
Image card2;
So I'm trying to make an applet that displays images of cards. The applet has a deck of 52 playing card images. It should shuffle the deck with a random number generator and display the first 10 cards of the shuffled deck.
With this code I have about 100 errors and I'm not sure what I'm doing wrong: I know I have to use arrays in order to ultimately display the images, but do I have to create Image objects for the Image [] cards array? I am getting many "class, interface, enum expected" errors as well as others.
import java.util.Random; import java.awt.Image; import java.applet.Applet; import java.awt.Graphics; public class unit12 extends Applet {
So I'm trying to make an applet that displays images of playing cards. The applet should load a deck of 52 playing card images (the folder is called "images"). The applet should shuffle the deck (using a random number generator) and display the first 10 cards of the shuffled deck. I then have to display the cards in two rows of five cards each.
With this code I have about 100 errors and I'm not sure what I'm doing wrong:
Basically I started writing my code in one class, then I split it up into a Card class and a DeckOfCards class and I now need to figure out how to get it all to work together. I get a little confused with calling methods sometimes, especially when separate classes are in play. I think I just need a method to deal out . Besides getting it all working together correctly. I'm also having trouble creating the method to deal out five cards that also tells how many cards are left in the deck and I believe I need a toString method but I honestly do not know how to go about that.
Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value. Then create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a card and report the number of cards left in the deck. The shuffle methods should assume a full deck. Create a driver class (CardsGame) with a main method that deals five cards from the shuffled deck, printing each card as it is dealt. Make sure to write the appropriate constructors, getters, setters, toString and other methods as required for both classes.
The main class, CardsGame Class
import java.util.Scanner; public class CardsGame { public static void main (String [] args) { DeckOfCards deck = new DeckOfCards(); //call shuffle deck.shuffle();
I have an assignment for my summer class. Basically I started writing my code in one class, then I split it up into a Card class and a DeckOfCards class and I now need to figure out how to get it all to work together. I get a little confused with calling methods sometimes, especially when separate classes are in play. I think I just need a method to deal out . Besides getting it all working together correctly. I'm also having trouble creating the method to deal out five cards that also tells how many cards are left in the deck and I believe I need a toString method but I honestly do not know how to go about that. FYI, I think the prof would rather arrays then enums since we're dealing with arrays right now hence the array for the 52 card deck.
Here are the directions...
Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value. Then create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a card and report the number of cards left in the deck. The shuffle methods should assume a full deck. Create a driver class (CardsGame) with a main method that deals five cards from the shuffled deck, printing each card as it is dealt. Make sure to write the appropriate constructors, getters, setters, toString and other methods as required for both classes.
The main class, CardsGame Class
Java Code:
import java.util.Scanner; public class CardsGame { public static void main (String [] args) { DeckOfCards deck = new DeckOfCards(); //call shuffle deck.shuffle();
I have to random shuffle an array of Card Objects which does the funcion of a deck. Heres the code:
Java Code:
public void barajear(){ int j; for (int i=0;i<52;i++){ j=Baraja.random(51); if (this.mazo[j]==null){ this.mazo[j]=this.arreglo[i]; }else{ --i; } } } mh_sh_highlight_all('java');
so bassically theres an array called "arreglo" which has the cards in order and the function "random" its an rng of numbers from 0 to 51.what i'm trying to do it's to take the cards from the ordenated array and put them randomly in the other but only if it's empty.(the array "mazo" has alredy been initialized with null).it worked at first, but now, after compiling succesfully i tried to run it and the cmd just...
Assuming we have an array that is int[] cardDeck = new int[52] and each card is given a value with the following method; this deck does not include Jokers. Note: 11, 12, and 13 and used to represent Jacks, Queens, and Kings respectively, and 1 is used to represent Aces.
Java Code:
public static void loadDeck(int[] cardDeck) { for(int i = 0; i < cardDeck.length; i++) { if(i+1 > 39) cardDeck[i] = i+1-39; else if(i+1 > 26)
I have red underlines under "Card" and "cards" in my Deck class and "deal" in my driver and i don't know how to fix them to get it to properly run.
Card Class:
Java Code:
public class Card { public final static int ACE = 1; // note: or use enumerated types public final static int TWO = 2; public final static int THREE = 3; public final static int FOUR = 4; public final static int FIVE = 5; public final static int SIX = 6; public final static int SEVEN = 7;
I am trying to make a program that will make a deck of 52 cards, but not shuffle it. I can't get rid of the errors in the code that I have so far.
Java Code:
public class Deck { private Card[] deck; private int cardsUsed; public Deck() { deck = new Card[52]; int cardCt = 0; for ( int suit = 0; suit <= 3; suit++ ) { for ( int value = 1; value <= 13; value++ ) { deck[cardCt] = new Card(value,suit); cardCt++; } } cardsUsed = 0; } } mh_sh_highlight_all('java');
I am getting red squiggly lines on lines:
#3 under "Card" #8 under "deck" and "Card" #12 under "deck" and "Card"
I redid my entire code to use array-lists instead of just arrays my professor finally got back to me and said he doesn't want us to use lists. The assignment is to create a CardGame driver class, then create a "card" in a card class, then a "deck of cards" in a DeckOfCards class, shuffle, and deal 5 random cards and "deal a card and report the number of cards left in the deck". That last line in quotes is what I do not know how to do.
Also, I renamed a lot of variables via some suggestions and the assignments states "Make sure to write the appropriate constructors, getters, setters, toString and other methods as required for both classes." I think they're appropriate. Should I change some of he methods to better getters and setters identifiers?
Here is my code.
import java.util.Random; public class CardsGameTest { //execute application. public static void main(String[] args) { DeckOfCards myDeck = new DeckOfCards(); myDeck.shuffle(); //shuffle cards.
[code].....
The instructions also say to "print each card as it is dealt" does that mean 5 cards one at a time? Anyways, I was thinking that in the driver class I could add a for loop to the for loop and as it deals a card it could run through the second for loop and print how many cards are left in the deck.
I am trying to assign random numbers to a deck of cards without repeating the numbers. What am I doing wrong?
package hokm; import java.util.Random; import java.util.Scanner; public class Hokm { public static void main(String[] args) { int [][] number=new int[52][2];
I am creating a deck of 52 cards each with their rank(1 2 3...King, Ace) and suit(Clubs... Spades).
I want to be able to print out value of each card after creating them such as - 2 of CLUBS and so on. I am able to do that now. Only problem is, when it comes to the picture cards, I am representing them with numbers 11(Jack), 12(Queen) 13(King) and 14(Ace). I can't quite get around to changing the numbers to be represented as the actual words (King and so on).
I imagine that I should store the jack,queen,king,ace values in an enum too and call it in my loop but can't quite get it. Should I have like a 3rd for loop in my following codes to make it work?
Java Code:
//My main method. The Card class follows below
public static void main(String[] args) { Card[] cards = new Card[52]; int i = 0; for (Card.Suits suit : Card.Suits.values()) { for (int y = 2; y < 15; y++) { cards[i] = new Card(y, suit.name()); i++;
1 - I don't understand why I'm getting an empty stack error when calling the removecard method in my Table class line 13?
2 - I am trying to use a constructor to populate my deck of cards instead of a method when creating my theDeck object in my Table class line 11 but I get the following error:
java.lang.StackOverflowError at java.util.Vector.<init>(Unknown Source) at java.util.Vector.<init>(Unknown Source) at java.util.Stack.<init>(Unknown Source) at Deck.<init>(Deck.java:7) at Deck.<init>(Deck.java:34)
I have an applet that uses JPanels to draw images in. I want to include actual jpgs now instead. The applet points to a .jar file. I want to use any number of images here, do I have to include them all in the jar file or is there another way to "point" to them (like html)?
I have written a program to enter a name in a text box of an html file, get the name in a Servlet, search for the name in the database and inform the user whether or not the name is in the database via an applet. I'm trying to get the information from the applet to display in a colored oval, green w/white font if the name is in the database and red w/black font if the name is not in the database. I can get the information to display just not in the colored ovals and text that I want, I am including only the applet code, not the HTML or Servlet.
import java.applet.*; import java.awt.Color; import java.awt.Graphics; import java.sql.*; public class MyApplet extends Applet { public void paint(Graphics page){
The code below is just the GUI for a slot machine. Currently when play is clicked it displays the random number, I'm trying to make it so each random number displays an image in the GUI instead. For example if the random numbers were 2,2,3 it would display Cherry, Cherry, Bells. I started changing field1 to the image but realised I was on the wrong track as it would just display the same image not one allocated to a number. I've left in what I started doing.
how to do it?
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SlotMachineGUI { JPanel mainPanel; SlotMachine slotEngine;
I want to be able to get an image online and display on my JPanel but for some reason my image wont load and just shows a blank square, but when I try to load an image from my hard drive it works just fine.
I am supposed to create a method that simulates a perfect shuffle of a given array of integers. According to the assignmment, this is what a perfect shuffle is:
This procedure is called a perfect shuffle if the interleaving alternates between the two half-decks.Unfortunately, the perfect shuffle comes nowhere near generating all possible deck permutations.In fact, eight shuffles of a 52-card deck return the deck to its original state!Consider the following perfect shuffle algorithm that starts with an array named cards that contains 52 cards and creates an array named shuffled.
Initialize shuffled to contain 52 empty elements. Set k to 0. For j = 0 to 25, − Copy cards[j] to shuffled[k]; − Set k to k+2. Set k to 1. For j = 26 to 51, − Copy cards[j] to shuffled[k]; − Set k to k+2.
This approach moves the first half of cards to the even index positions of shuffled, and it moves the second half of cards to the odd index positions of shuffled.The above algorithm shuffles 52 cards. If an odd number of cards is shuffled, the array shuffled has one more even-indexed position than odd-indexed positions. Therefore, the first loop must copy one more card than the second loop does. This requires rounding up when calculating the index of the middle of the deck. In other words, in the first loop j must go up to (cards.length + 1) / 2, exclusive, and in the second loop j most begin at (cards.length + 1) / 2.
For a project we have to "shuffle" items in an array using random numbers. We are supposed to generate random numbers and use those numbers to exchange array elements. But I am not sure what that means, "exchange array elements". Does that mean you generate 2 random numbers within the length of the array, and then switch the items at those locations in the array?
Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:205) at GUI.<init>(GUI.java:26) at Apples.main(Apples.java:7)
i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.
I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.
I'm not getting any errors, just i can't seem to stop the music from playing after clicking the jbutton "Sound On" / "Sound Off" again. I've tried a few methods but it just isn't working for me.