Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java: Start implementing the project for the class using the command line int

ID: 3763842 • Letter: I

Question

In Java: Start implementing the project for the class using the command line interface (i.e., the console). The Wheel of Fortune is an American television game show created by Merv Griffin in 1975. The game consists of two components: the word phrase/letters board and the wheel of prizes. The board consists of a short phrase or message, and at the beginning of the game all its letters are all hidden. An underscore (“_”) will represent a hidden character. The wheel consists of numerous wedges, each possessing either a prize value or the phrase “bankrupt”. Our simplified game will have two players: a human (i.e., the user) and the computer. The players are supposed to guess a phrase chosen randomly by the computer from an input file (see test_examples.txt). Each player gets a turn. The human player turn starts the game. In each turn, a player can either choose to guess a letter or guess the entire phrase. Before guessing, the player needs to spin the wheel. The pleyer enters a letter and the prize value from the wheel multiplied with the number of the letter occurences will be added to the total prize of the player if the player makes a correct guess. Moreover, all the occurrences of a correctly guessed letter will be displayed on the board at the appropriate positions. The letters that have not been guessed by players will remain hidden. The “bankrupt” wedge will restore a player’s score to 0. If the player guesses correctly he will play another turn. The player that guesses the phrase first will win the game. The number of points possible for the project are 40 points: - game preparation and play one turn by the human user (read the file of input phrases/book titles and select a random input, show the hidden letters, let the user to choose a letter, win or lose and replay if necessary) = 10 points - play one turn by the computer = 10 points - play the game to completion correctly = 10 points - graphical user interface = 10 points

Explanation / Answer

Answer :

PrintBoard.java

public class PrintBoard extends ArrayList<Character> {

private String name;
private boolean[] visibility;

public PrintBoard(CharSequence name) {
initializeWith(name);
}

public PrintBoard initializeWith(CharSequence name) {
this.name = name.toString().toUpperCase();
visibility = new boolean[name.length()];
char c;
for (int i = 0; i < visibility.length; i++) {
visibility[i] = false;
c = Character.toUpperCase(name.charAt(i));
add(Character.isLetter(c) ? ' ' : c);
}
return this;
}

public boolean reveal(char character) {
Character c = Character.toUpperCase(character);
boolean sentenceContainsChar = false;
for (int i = 0; i < name.length(); i++) {
if (name.charAt(i) == c) {
sentenceContainsChar = true;
visibility[i] = true;
set(i, c);
}
}
return sentenceContainsChar;
}

public String name() {
return name;
}

}

Calculate.java

public class Calculate{

private int amount;

public Calculate(int amount) {
this.amount = amount;
}

public int credit(int amount) {
return this.amount += amount;
}

public int debit(int amount) {
return this.amount -= amount;
}

public int amount() {
return amount;
}


public String toString() {
return String.format("[amount=%d]", amount);
}

}

Admin.java

public class Admin{

private PrintBoard board;

public Admin(PrintBoard board) {
this.board = board;
}

public void doWhatsNecessaryWith(Player player, SpinResult spinResult) {
  
switch (spinResult.type()) {
case CASH:
player.account().credit(spinResult.amount());
break;
case LOSE_A_TURN:
  
break;
case BANKRUPT:
  
break;
case SOLVE_PUZZLE:
  
break;
}
}

public boolean uncoverConsonant(char consonant) {
boolean isConsonant = false;
  
isConsonant = true;
  
if (isConsonant)
return board.reveal(consonant);
else
return false;
}

public boolean solveWith(CharSequence solution) {
return solution.equals(board.sentence());
}

public void giveVowel() {

board.reveal('a');
}

}

Participant.java

public class Participant {

public enum Choice {
SPIN_WHEEL, BUY_VOWEL
}

private String names;
private Calculate account;
private Admin host;

public Participant(String name, Calculate account, Admin host) {
this.name = name;
this.account = account;
this.host = host;
}

public Calculate account() {
return account;
}

public void buyVowel() {
host.giveVowel();
}

}

public boolean guessConsonant(char consonant) {
return host.uncoverConsonant(consonant);
}

public SpinResult spin(Wheel wheel) {
return wheel.spin();
}

public void giveToHost(SpinResult spinResult) {
host.doWhatsNecessaryWith(this, spinResult);
}

public boolean solveWith(CharSequence solution) {
return host.solveWith(solution);
}

public void acceptCashGift(int amount) {
account.debit(amount);
}

public String names() {
return names;
}

  
public String toString() {
return String.format("[name=%s, account=%s]", names, account);
}

}

CircleWheel.java

public class CircleWheel{

public enum SpinResultType {
CASH, LOSE_A_TURN, BANKRUPT, SOLVE_PUZZLE
}

public SpinResult spin() {
  
return new SpinResult(SpinResultType.CASH, 100);
}


public class SpinResult {
private SpinResultType type;
private int amount;

public SpinResult(SpinResultType type) {
this(type, 0);
}

public SpinResult(SpinResultType type, int amount) {
this.type = type;
this.amount = amount;
}

public SpinResultType type() {
return type;
}

public int amount() {
return amount;
}

  
public String toString() {
return String.format("[type=%s, amount=%s]", type, amount);
}

}

}

Play.java

public class Play {

public static void main(String[] args) {

String name = "The answer is forty-one!";
PrintBoard board = new PrintBoard(name);
CircleWheel wheel = new CircleWheel();
Admin host = new Admin(board);

List<Participant> players = new ArrayList<Participant>();
players.add(new Player("Micheal", new Calculate(0), host));
players.add(new Player("John", new Calculate(0), host));

for (Participant player : players) {
System.out.printf("Participant: %s%n", player.name());

String niceTry = "good try";
System.out.printf("Solved with '%s'? %b%n", niceTry, player.solveWith(niceTry));

SpinResult sr = player.spin(wheel);
System.out.printf("SpinResult %s%n", sr);
player.giveToHost(sr);
System.out.println(player);

System.out.printf("x good guess? %-5b %s%n", player.guessConsonant('x'), board);
System.out.printf("t good guess? %-5b %s%n", player.guessConsonant('t'), board);
player.buyVowel();
System.out.printf("Bought vowel: %s%n", board);

System.out.println();
}
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote