I curious for tips for moving forward within my current code for my counting cards GUI interface. I need two labels one for the card deck, and the other for the randomized card face. When the card face shows, in the count value text field the value of the card is added. For each card this is to happen through until the whole deck. There is also a card count text field to count how many cards have been dealt out. Now with that being said, I am being held back by getting the two labels to show in my GUI, the buttons show, but I need getting the cards and its value to show and initialize, with the card count in the card count text field.
import java.lang.Math;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CardsGui extends JFrame
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();
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'm trying to make a random card shuffler but the output would sometimes have same value multiple times. For example it might print out A5 at the fifth index then print out A5 again as the 32 index.
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 have tried to add a scroll bar line 28 - 31 and can't figure out why its not working. Its not even showing the scroll bar!
public class TheFrame extends JFrame { private static ThePanel canvas; private String deckImagesToUse; /** * The constructor creates a Frame ready to display the cards */ public TheFrame(String cardImgFile) {
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:
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++;
"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;
I am trying to sort the 5 cards in decreasing order and this is exactly what my professor gave us but it has errors.
int pos; int max; for (pos = 0; pos < hand.length; pos++){ max = pos; for (int i = pos + 1; i < hand.length; i++){ if (hand[max] < hand[i]){ max = i; } } if (max != pos){ int temp = hand[pos]; hand[pos] = hand[max]; hand[max] = temp; } } }
Line 6 has an error with the < operator. Line 11&13 says cannot convert from card to Int. This method is passing in Card[] hand
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)
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 {
I have a string of variable tags (tag) filled with variables, and using a Scanner (scan) to manipulate and generate data dictionary add cards for each. The variables are delimited with new line character, and the variables are structured such that the actual name of the variable contains info as to its data type, size, etc. What I need to do is move the scanner to a particular point into the string then use .nextInt() or similar. I don't want to do this to the whole variable, just where I start it from. How can I do this?
Scanner scan = new Scanner( tag ); int ptr = tag.indexOf( "_" ); ptr++; if ( Character.toLowerCase( tag.charAt( ptr ) ) == 's' ) // then start at the "_" character and grab the nextInt()
I have written a piece of code that takes a desired input file and calculates things such as words, characters, digits etc. I would like to make the program look better by counting palindromes.what I could add to my current code to count palindromes.My current code for counting other things that I would like to add plaindromes to.
// Loops through the file calculating the outcome. while (input.hasNextLine()) { lines++; String line = input.nextLine(); chars += line.length();
I'm having trouble creating a highly efficient algorithm for counting within a custom scale. This problem applies to futures trading, specifically treasuries contracts.
One specific treasury contract has 32 units before rolling over to the next whole number. So, the price scale looks something like this ...
If I pick a number (price) at random, let's say 1 28, and I want to add 8 units to that value, I should end up with 2 4. I can do this using brute force, calculating remainders, etc, etc....
Write a method compressDuplicates that accepts a stack of integers as a parameter and that replaces each sequence of duplicates with a pair of values: a count of the number of duplicates, followed by the actual duplicated number. For example, suppose a variable called s stores the following sequence of values:
This new stack indicates that the original had 5 occurrences of 2 at the bottom of the stack followed by 2 occurrences of -5 followed by 4 occurrences of 3, and so on. This process works best when there are many duplicates in a row. For example, if the stack instead had stored:
bottom [10, 20, 10, 20, 20, 10] top
Then the resulting stack after the call ends up being longer than the original:
bottom [1, 10, 1, 20, 1, 10, 2, 20, 1, 10] top
If the stack is empty, your method should not change it. You may use one queue as auxiliary storage to solve this problem. You may not use any other auxiliary data structures to solve this problem, although you can have as many simple variables as you like. You may not use recursion to solve this problem. For full credit your code must run in O(n) time where n is the number of elements of the original stack.
I wrote a code but still having a problem with it , am I allowed to use 3 while loops ?
public void compressDuplicates(Stack<Integer> s ){ Stack<Integer> backup= new Stack<Integer>(); int count = 1; while(!s.isEmpty()){ int temp = s.pop();
It's supposed to count all of the duplicates in an array and print out how many occurrences of the value starting at whatever index, or if there are no duplicates state that. Basically:
No duplicates with value 1 beyond Index 0
There are 3 more occurrences of value 2 starting at index 1
There are 2 more occurrences of value 2 starting at index 2....
This is what I've got so far:
Java Code:
public static void main(String[] args) { int[] arr = {1, 2, 2, 3, 4, 2, 4, 3, 0, 5, 3, 2}; for(int i = 0; i<arr.length; i++){ int count = 0; for(int j = i+1; j<arr.length; j++){ if((arr[j] == arr[i]) && (i!=j)){ count++; System.out.print("There are " + count + " more occurrences of "); System.out.println(arr[i] + " starting at index " + i); } } } } mh_sh_highlight_all('java');
I was browsing around and I found a question asking to find how many times a word occurred in a sentence. I am using a hashtable, over kill yes but I need to use them more. However my counter is not working, not really sure why.You can see in the main method I have two repeating names but it returns 0.
package frequency; import java.util.Hashtable; public class CheckFrequency { hashtable<String, Word> words = new Hashtable<String, Word>();
Complete the body of the following method. Use a CharQueue to store the input line as it is being read. The parameter is an EasyReader from Appendix B of the text. Use the method in.charInput( ) to read and return the next character of the EasyReader, and use in.isEOLN( ) to determine whether the next input character is the end-of-line.
public static int counter(EasyReader in) // Precondition: There is a line of input waiting to be read from in. // Postcondition: A line of input has been read from in, up to but not // including the newline character. The return value of the method // is the number of times that the LAST character of the line appeared // somewhere in this line.
[EXAMPLE Input: ABBXDXXZX - The value returned by counter would be 4 for this input since there are 4 X's in the input line.]
***When I look at this I understand that I'm being asked to finish the method, that I have 1 input, which is an "EasyReader" object called in and that I use a CharQueue object along with the method isEOLN( ) to grab characters from in while looking for an end of line and then sticking the values in the queue and then I can go through the queue and figure out the number of times that last character shows up in the queue. I just am at a loss on the "how".