Write an application in Java that allows a user to play the game Bulls and Cows against a computer. The game works as follows: The computer chooses a 4-digit number in secret. The digits must all be different. The user then guesses the number and the computer provides the number of matching digits. If the matching digit is in the right position it is a "bull", if it is on a different position it is a "cow". For example:

Computer chooses: 3691

User guesses: 1649

Computer answers: 1 bull and 2 cows

If the user guesses a number with repeat digits that is partially correct the rule is that a correct digit can only count once and bulls count before cows. So for example

Computer chooses: 3691

User guesses:   4211

Computer answers: 1 bull and 0 cows

Your program should report the number of attempts the user needed to guess the number at the end of the game.

Your program should consist of two additional classes: Game and Oracle. All input and output should happen in the Game class. This is where you will ask the player for their guess and this is where you will tell the player how many bulls and cows they got. The Oracle class should store the actual computer choice as a String and have methods to determine how many bulls and cows any given guess would generate.

For aspiring hackers: Write a class that computerizes the human user and requires on average less than 8 turns to guess the pattern. Write a new test class and a Simulator class (the Simulator class will sub for the Game class) to demonstrate this ability by playing 1000 games of computer versus computerized user and reporting the average number of guesses.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Game{

    private int turns;
    private Oracle computer;
    private Scanner input;

    // you may need more instance variables here
    private int attempt;
    private boolean gameover;

    public Game(){
    // your code for the Game constructor goes here
       turns = 0;
       computer = new Oracle();
       input = new Scanner(;
       attempt = 0;
       gameover = false;

    public void playGame(){
    // your code for the Game playGame method goes here
       char c;
       while (true) {            
            if (gameover) {...
$15.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats