Question
Bulls and Cows is a word game, where you try to guess a particular word. For example, let's imagine the word you are trying to
Bulls and Cows is a word game, where you try to guess a particular word. For example, let's imagine the word you are trying to guess is "march". As a player you type in words that you think might be the right word, and it tells you how many Cows you got and how many Bulls you got. Let's say your first guess is "trash". It would respond "Bulls: 1 Cows: 2". This is because the letter h at the end of "trash" is the same letter as the last letter of "march". This is called a Bull, you got one Bull. You got 2 cows because "trash" and "march" both have an r and an a, but they are in different locations. These are called cows. So for "trash" it would say Bulls: 1, Cows: 2. Using that information you'd make another guess. For example, your second guess might be "april". In that case it'll reply: Bulls: 1, Cows 1 (because the r is correct and in the right place, and the a is correct, but in the wrong place). You would continue guessing until you correctly guess the actual word. For this question you'll need to write a method called bullsAndCows() that takes in the correct word, and the guessed word (both strings), and returns how many bulls and cows you have (as a string). You'll probably want to convert the strings to character arrays to do this work. In your Driver class's main method you'll set the correct word to "march", then you'll prompt the user for their guess, call the bullsAndCows method to get the score of that guess, and tell the user. You'll allow the player to keep guessing until they get the word correct. Things your program must deal with successfully: The user may guess any length word. Your program should still function correctly. The user may enter their guess with any capitalization, you should convert the guess to lowercase before you pass it to bullsAndCows(). Sample output: Enter your guess: trash Bulls: 1 Cows: 2 Enter your guess: april Bulls: 1 Cows: 1 Enter your guess: Bulls: 1 Cows: 1 Enter your guess: apple Bulls: 0 Cows: 1 Enter your guess: hi Bulls: 0 Cows: 1 Enter your guess: h Bulls: 0 Cows: 1 Enter your guess: r Bulls: 0 Cows: 1 Enter your guess: m Bulls: 1 Cows: 0 Enter your guess: march Bulls: 5 Cows: 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started