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

  • Home
  • SEARCH
  • 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 8669361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:27:21+00:00 2026-06-12T18:27:21+00:00

Before I start, yes this is a homework assignment so obviously I am not

  • 0

Before I start, yes this is a homework assignment so obviously I am not asking for any answers but I would appreciate if anyone could help me in the right direction or give me some advice.

Ok so for an assignment I am making a game of black jack in java. Currently I have a Card class, a Deck Class, and my Main (CardGameTester). Right now I only am doing the game with one player (the user) so it’s pretty basic. My main is quite messy and I could do with having a third class but I’ve decided to do it this way instead.

I’m getting several strange errors that I believe are me messing up my arraylists or something to do with the objects. If anyone could help me out I would really appreciate it because I am quite stuck at the moment.

the errors I’m getting when I try to compile:

6 errors and 1 warning found:
--------------
*** Errors ***
--------------
File: E:\Documents\Java Files\Assignment 3\CardGameTester.java  [line: 17]
Error: The method add(Card) in the type java.util.ArrayList<Card> is not applicable for the arguments (Deck)
File: E:\Documents\Java Files\Assignment 3\CardGameTester.java  [line: 28]
Error: The method add(Card) in the type java.util.ArrayList<Card> is not applicable for the arguments (Deck)
File: E:\Documents\Java Files\Assignment 3\CardGameTester.java  [line: 35]
Error: Type mismatch: cannot convert from Card to int
File: E:\Documents\Java Files\Assignment 3\Deck.java  [line: 15]
Error: The constructor Card() is undefined
File: E:\Documents\Java Files\Assignment 3\Deck.java  [line: 19]
Error: The method shuffle() is undefined for the type java.util.ArrayList<Card>
File: E:\Documents\Java Files\Assignment 3\Deck.java  [line: 30]
Error: c cannot be resolved
-------------
** Warning **
-------------
File: E:\Documents\Java Files\Assignment 3\Card.java  [line: 5]
Warning: The field Card.suits is never read locally

Here is Card.java

public class Card
{
  private int rankValue, suitValue;
  private String ranks[] = {"Hearts", "Clubs", "Spades", "Diamonds"};
  private String suits[] = {"Ace", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};

  public Card(int rank, int suit)
  {
    rankValue = rank;
    suitValue = suit;
  }

  public String convertToString(int rank){
    return ranks[rank];
  }

  public void setRank(int rank){
    rankValue = rank;
  }

  public void setSuit(int suit){
    suitValue = suit;
  }

  public int getRank(){
    return rankValue;
  }

  public int getSuit(){
    return suitValue;
  }

  public String toString(){
    return "Rank: " + rankValue + "Suit: " + suitValue;
  }
}

Here is Deck.java:

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Deck
{
  private ArrayList<Card> cards = new ArrayList<Card>();

  public Deck()
  {
    for(int a = 1; a <= 4; a++)
    {
      for(int b = 1; b <= 13; b++)
      {
        Card c = new Card();
        cards.add(c);
      }
    }
    cards.shuffle();
  }

  public void shuffle(){
    Collections.shuffle(cards);
  }

  public String deal(){
    int index = 0;
    cards.get(index);
    cards.remove(index);
    return "You have been dealt a: " + c.toString();
    index++;
  }
}

and here is my Main CardGametester.java:

public class CardGameTester
{
  public static void main(String[] args)
  {
    ArrayList<Card> hand = new ArrayList<Card>();
    Deck d = new Deck();

    Scanner scan = new Scanner(System.in);
    System.out.println("Welcome to the game of Black Jack!\nWould you like to Start?");
    String input = scan.nextLine();
    if(input == "yes")
    {
      d.deal();
      hand.add(d);
    }

    String input2;

    while (input2 == "yes")
    {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Would you like to hit or stay?");
      input2 = keyboard.nextLine();
      d.deal();
      hand.add(d);
    }

    int total;

    for(int index = 0; index <= hand.size(); index++)
    {
      total = hand.get(index);
    }

    System.out.println("Your total value for you cards are: " + total);

    if(total <= 21){
      System.out.println("Congrats, you have won for not going over 21");
    }
    else
      {
        System.out.println("Sorry, you lose for going over 21");
    }
  }
}
  • 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-12T18:27:23+00:00Added an answer on June 12, 2026 at 6:27 pm

    You have an ArrayList of Card but are trying to add a different type of Deck:

    ArrayList<Card> hand = new ArrayList<Card>();
    
    hand.add(d); // d = Deck
    

    It would be better to return the index of the card in the Deck.deal to keep track of what card is in your hand.

    Also, you are calling:

    Card c = new Card();
    

    but the constructor takes 2 arguments:

    public Card(int rank, int suit)
    

    There 2 errors here in the deal method:

    ...
    return "You have been dealt a: " + c.toString();
    index++;
    ...
    

    Firstly as Card c will defined here. You could use:

    Card c = cards.remove(index);
    

    Secondly, no statements are allowed after return statements, so index++ cannot appear here.

    Next:

    Error: Type mismatch: cannot convert from Card to int

        total = hand.get(index);
          ^            ^
       int type     Card type
    

    You are calling a non-existent method on ArrayList

    cards.shuffle();
    

    You already have this in a method so you could call

    shuffle();
    

    While not a compilation error, the use of == will cause your input Strings not to be evaluated correctly, so change

    if (input == "yes")
    

    to

    if ("yes".equals(input))
    

    Consider using enums for managing the card rank & suit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I start, yes this is a homework. I would not have posted here
Before I start: YES, this is a homework from college. Before I get told
Disclaimer before the uppity types start in: This is not to be deployed in
(Before I start, yes I have asked a similar question before; unfortunately due to
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
I usually try to do TDD with not much analysis (no diagrams) before start
before I start I want to point out that I tagged this question as
Guys before you start down voting me please read this question and please understand
(before I start I should say yes, I have done all the stupidity checks,
Not having worked with Objective C before I thought I would give a stab

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.