Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:54:53+00:00 2026-06-10T09:54:53+00:00

I have my primary class running, and I wanted to run a separate class

  • 0

I have my primary class running, and I wanted to run a separate class to shuffle numbers, then return the shuffled numbers into my primary class. In my shuffle class I have the return statement… but now what do I do? How do I use the random order of my int array in my primary class?

Here is my shuffle class:

public class Shuffle {
public static int[] getShuffle() {
    int[] cards = new int[52];
    ArrayList<Integer> cards_objs = new ArrayList<Integer>();

    for (int i = 0; i < cards.length; i++) {
        cards_objs.add(i);
    }

    Collections.shuffle(cards_objs);

    for (int i = 0; i < cards.length; i++) {
        cards[i] = cards_objs.get(i);

    }

    return cards;
}

}

I am making a card game(if you cant tell);

I wanted to use this shuffle class so that the cards are shuffled… but no card appears more than once.

when I return cards, how do I use them in my game class?
for example if the first number in the array is 1, then the card is Ace of clubs,
if the number is 2, then the card is Ace of diamonds. and so on…
I apologize for not posting enough information… I am new to java (as you can tell)

all help will be greatly appreciated,

-Steve

EDIT:
I found out what my problem was, I don’t think I made it clear enough what my question was. Nonetheless thank you all for your help, it gave me ideas on different ways to approach this project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:54:54+00:00Added an answer on June 10, 2026 at 9:54 am

    I think using enum you can implement Card Game in a better way.

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    
    // This is just sample example  and it is just to show an approach. I had not enough time    to make code perfect but it works fine.
    public enum Deck
    {
    DECK;
    enum Rank
    {
        DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6),
        SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11);
    
        Rank(int rank)
        {
            this.rank = rank;
        }
    
        private final int rank;
    
    }
    
    enum Type
    {
        SPADES,
        HEARTS,
        DIAMONDS,
        CLUBS;
    }
    
    class Card
    {
        private final Rank rank;
        private final Type type;
    
        Card(Rank rank, Type type)
        {
            this.rank = rank;
            this.type = type;
        }
    
        @Override
        public String toString()
        {
            return type.name() + rank.name();
        }
    
    }
    
    static List<Deck.Card> cards = new ArrayList<Deck.Card>();
    static
    {
        for (Rank rank : Deck.Rank.values())
        {
            for (Type type : Deck.Type.values())
            {
                cards.add(DECK.new Card(rank, type));
            }
        }
    
    }
    
    List<Deck.Card> shuffle()
    {
        Collections.shuffle(cards);
        System.out.println(cards);
        System.out.println(cards.size());
        return Collections.unmodifiableList(cards);
    }
    
    public static void main(String[] args)
    {
        DECK.shuffle();
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running into a very frustrating bug. I have a java class that reads
I define a base class which have a Long primary key , just like
I have a primary class and an extended one (database connections). Parent Classname Classica
So I have a class that has a composite primary key: public class Field
I have a POCO class, mapping to a table that basically contain three primary
I am trying to do a basic belongs_to/has_many association but running into a problem.
I have a model: class MyModel(models.Model): id = models.IntegerField(primary_key=True) recorded_on = models.DateField() precipitation =
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have the following models: class Profile(models.Model): verified = models.BooleanField(default=False) primary_phone = models.OneToOneField('Phone', related_name='is_primary',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.