Question: Programming Assignment: Class: Country Description: In this assignment you will work on modeling the wheel of fortune game where a phrase/word must be guessed. To

Programming Assignment:

Class: Country Description: In this assignment you will work on modeling the wheel of fortune game where a phrase/word must be guessed. To do so, you will write the Country.java class which can be instantiated into an object. In this game, the user will be guessing a country. The methods to check the user's guesses will be part of the Country.java class. Here's a template for Country.java. Complete the Country.java class and use the TestCoutry.java class to test your work. The class will hold a data field that stores a country name from an array of countries.

The methods and constructors you are to work on are the following:

  • Country - constructor to initialize data fields: String country, int remainingGuesses, String displayWord 
  • guessLetter - method to that takes a guess (String) as an argument and checks how many times guess is in data field country. Method calls correctGuess method. 
  • solve - method that takes a guess (String) as an argument and returns true if guess equals data field country and false otherwise 
  • correctGuess - private method that takes a guess (String) and occurrences (int) as arguments. Method updates displayWord such that the * symbol is replaced with correct guesses. In addition, it calls the solve method to check if country has been guessed 
  • incorrectGuess - private method that takes a guess (String) as an argument and reduces the data field remainingGuesses by one 

Here is the Template of Country.java:

public class Country_Template { //data fields (instance and static variables) private static String[] countriesArray = {"Mexico", "Argentina", "Uruguay", "Chile", "England", "Spain", "UnitedStates", "Canada", "Cuba", "Venezuela", "CostaRica", "Italy", "Russia", "China", "India", "Japan", "Thailand", "Portugal", "South Africa", "Australia", "Germany", "Austria", "Poland", "Netherlands", "Sweden", "Finland", "Iraq", "Iran", "Brazil", "Ecuador", "Turkey", "NewZealand", "Bolivia", "Peru", "Colombia", "Egypt", "Mongolia", "NorthKorea" }; private static String category = "Country"; private String country; private int remainingGuesses; private String displayWord; public Country(){ //intialize country to a random country from countriesArray //create a random index value between 0 and this.countriesArray.length //set this.country to countriesArray[index] //set remainingGuesses to length of this.country //initialize displayWord to all * (should have same length as this.country) } public int getReaminingGuesses(){ return this.remainingGuesses; } public boolean guessLetter( String guess ){ //create an initialize three local variables: guessCount, guessInCountry, solvedWord //Traverse this.country and count the number of times guess is in this.country //update guessCount appropriately and set guessInCountry to true //If guessInCountry is true place a call to correctGuess method //provide guess and guessCount as arguments to correctGuess //set solvedWord to value returned by correctGuess method //else call incorrectGuess method //return solvedWord return false; } public boolean solve( String guess ){ //if guess equals this.country return true, else return false return false; } private boolean correctGuess( String guess, int occ ){ //private method called by guessLetter method (not accessible outside of this class) //Display number of occurrences of guess in this.country //Create temporary String to store the following: //Letter for letter, traverse this.country //if guess is in this.country add guess to temporary String //else add corresponding character of displayWord to temporary String //Set displayWord equal to temporary String //display displayWord //display remainingGuesses //call solve method and provide displayWord as an argument //return boolean value received by solve method return false; }

private void incorrectGuess( String guess ){ //Method displays that guess is not in this.country //Reduce remainingGuesses //Display remainingGuesses } }

Sample Output country "Portugal"

Would you like to solve?[yes/no] no Enter guess: a There are 1 a's Country: ******a* You have 8 guesses left Would you like to solve?[yes/no] no Enter guess: e There are no e's in your country You have 7 guesses left Would you like to solve?[yes/no] no Enter guess: i There are no i's in your country You have 6 guesses left Would you like to solve?[yes/no] no Enter guess: u There are 1 u's Country: ****u*a* You have 6 guesses left Would you like to solve?[yes/no] no Enter guess: p There are 1 p's Country: p***u*a* You have 6 guesses left Would you like to solve?[yes/no] yes Enter country: portugal You Won! You know your countries.

Sample Output country "Chile"

Would you like to solve?[yes/no] no Enter guess: i There are 1 i's Country: **i** You have 5 guesses left Would you like to solve?[yes/no] no Enter guess: a There are no a's in your country You have 4 guesses left Would you like to solve?[yes/no] no Enter guess: e There are 1 e's Country: **i*e You have 4 guesses left Would you like to solve?[yes/no] no Enter guess: r There are no r's in your country You have 3 guesses left Would you like to solve?[yes/no] no Enter guess: o There are no o's in your country You have 2 guesses left Would you like to solve?[yes/no] no Enter guess: p There are no p's in your country You have 1 guesses left Would you like to solve?[yes/no] no Enter guess: l There are 1 l's Country: **ile You have 1 guesses left Would you like to solve?[yes/no] no Enter guess: w There are no w's in your country You have 0 guesses left You need to study your countries more!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!