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 7868241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:56:26+00:00 2026-06-03T00:56:26+00:00

This is a code to play a guessing game that i made, but the

  • 0

This is a code to play a guessing game that i made, but the problem is that there were several issues which me as a beginner in java are not good at and need some guidance with. along the code there were some errors that i highlighted with an arrow on the side.

    import java.util.*;

public class GuessingGame
{


    private static Player house;
    private static Player player;

    private static int wins;
    private static int loses;
    private String name;
    int card1,card2;
    private int value;



    public void Player(String name){

        this.name=name;
        card1 = (Integer) null;
        card2 = (Integer) null;
    }



public void Card(int value){

     this.value = value;
    }





public int getValue(){
            return value;
        }



public void acceptDeal(Card card1, Card card2){
        Random r = new Random();
        int value = r.nextInt(13) + 1;
        card1 = new Card(value);            <<<<<<<<======= Error 1
        value = r.nextInt(13) + 1;
        card2 = new Card(value);            <<<<<<<<======= Error 2
    }



public static void init()
{

    house = new Player("House");                 <<<<<<<<======= Error 3
    player = new Player("Player");               <<<<<<<<======= Error 4
    wins = 0;
    loses = 0;

}


    public static void playGame() 
    {
       Scanner scan = new Scanner(System.in);

        char option, playAgain;
        int houseHandStrength, playerHandStrength;
        System.out.println("Welcome to our card guess 1.0 game!");
        System.out.println();

        do {
            // Deal cards to the house and player.
            house.acceptDeal(new Card(houseHandStrength), new Card(houseHandStrength));    <<<<<=== Error 5
            player.acceptDeal(new Card(playerHandStrength), new Card(playerHandStrength));  <<<<<=== Error 6    

            System.out.println(house);

            // Determine whether the player wants to play this hand.
            do {
                System.out.print("Deal cards? (Y/N) ");
                option = Character.toLowerCase(scan.next().charAt(0));
            }
            while (option != 'n' && option != 'y');

            if (option == 'y')
            {
                System.out.println(player);

                // Display hand strength of both players.
                houseHandStrength = house.getHandStrength();    <<<<<=== Error 7
                playerHandStrength = player.getHandStrength();  <<<<<=== Error 8
                System.out.println("The dealer's hand strength is: " + houseHandStrength);
                System.out.println("Your hand strength is: " + playerHandStrength);
                System.out.println();

                // If the player has a stronger hand.
                if (player.getHandStrength() > house.getHandStrength())
                {
                    System.out.println("** You won the hand! **");
                    wins++;
                }
                else {
                    System.out.println("The house wins this round!");
                    loses++;
                }
            }

            // Display the win/lose statistics.
            System.out.println("Current wins: " + wins);
            System.out.println("Current loses: " + loses);

            // Prompt whether the user wants to play again.
            do {
                System.out.print("Would you like to play again? (Y/N) ");
                playAgain = Character.toLowerCase(scan.next().charAt(0));
            }
            while (playAgain != 'n' && playAgain != 'y');           

            System.out.println();
            System.out.println("*******************************************************");
        }
        while (playAgain == 'y');

        System.out.println();
        System.out.println("Thank you for playing!");
    }

    public static void main(String[] args)
    {
        init();
        playGame();
    }
}
  • 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-03T00:56:28+00:00Added an answer on June 3, 2026 at 12:56 am

    First of all welcome to StackOverflow. It’s nice to see that you have found and used the homework tag. Keep in mind that for people to be able to help you, you need to give more information. What do you mean by error, what happens when you run the code etc

    regarding the errors you get, it appears as you haven’t really defined classes Card and Player, what you have there in your code are two methods GuessingGame.Card() and GuessingGame.Player() in your GuessingGame class. Change them to inner (or outer) classes and it should be fine 😉

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

Sidebar

Related Questions

When running a java applet that I made (a basic little number-guessing game), whenever
I use this code to play a MIDI file for my game, but I
Does play automatically cache data? I'm trying to read this code that someone else
ok i have question, i made this code to play axmediaplayer base on item
I am Using this code to play a .mp3 file from res/raw. The problem
Okay, this is part of the full code of a guessing game. public static
This is my code: import play.api.mvc._ import play.api.libs.json._ import play.api.libs.json.Json._ import play.api.libs.json.Writes._ class BaseController
Im planing on using this code to make random sounds play with an action,
This code used to return my local ip address as 192.xxx.x.xxx but now it
I'm trying to write a very simple number guessing game (code is below). After

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.