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

The software development house you work for has decided to create a prototype ba

ID: 3749582 • Letter: T

Question

The software development house you work for has decided to create a prototype based on the game Scrabble, but with a rwistthat will be used on mobile devices. They require a prototype from you that IS designed using a Java console application. If the prototype is a success the application will be developed for the mainstream mobile platforms. You are firstly required to prompt the user to enter in a one (1) to start the game. If the users decide to play the game prompt for the two (2) player names. Welcome to the WORD WARS game Press (1) To start the game Press any other key to exit the game Enter your selection: 1 Enter player 1 name: Andile Enter player 2 name: Sarm The players will then be presented with the alphabet. Each player has to enter a word with the available letters in the alphabet list. When a player enters a word the letters of that word get removed from the alphabet list. Only vowels are not removed from the alphabet list. Before a word can be accepted both players must agree if the word entered is valid or not. LETS PLAY WORD WARS!! Alphabet letters left: a bcdefghijkl m n oPst u v x y z Andile enter your word: java Enter () yes if both players agree on the word Alphabet letters left: a b c d e f g i k 1 n San enter your word: logie Enter (y) yes 1if both players agree on the word p q t u w x y z Alphabet letters left: a b d e f h i k Andile enter your word: n p q r t u w x y z It is suggested that players have a dictionary present to determine the validity of the word. If the word is accepted the player is awarded one point for ceach letter in the word. This letter tally will determine who the winner is when the game is finished. A letter can be used more than once in the creation of a word, but then must be removed from the alphabet list. For example, the word "FILL" contains two "L", which must be removed from the alphabet list.

Explanation / Answer

Java complete code:

import java.util.HashSet;

import java.util.Scanner;

import java.util.Set;

public class WordGame

{

static char alphabets[]=null;

static char vowels[]= {'a','e','i','o','u'};

static Set<Character> missingLetters =null;

static String player1Name = null,player2Name = null;

static String player1Word,player2Word;

static int player1Score=0,player2Score=0;

public static void main(String[]arg)

{

//Scanner class object to read inputs

Scanner scan = new Scanner(System.in);

//variable declaration and initialization

int selection;

player1Score=0;player2Score=0;

missingLetters=new HashSet<Character>();

alphabets=new char[] {'a','b','c','d','e','f','g','h',

'i','j','k','l','m','n','o','p',

'r','s','t','u','v','w','x','y','z'};

char ch1,ch2;

//do-while loop to display the game again

do {

//Displaying info on the console

System.out.println(" Welcome to the WORD WARS game. ");

System.out.println("Press (1) To start the game. ");

System.out.println("Press any other key to exit the game.");

System.out.print("Enter your selection:");

selection=scan.nextInt();

System.out.println("***************************************");

//if selection is 1,then go with game

if(selection==1)

{

//asking to enter two player names

System.out.print("Enter player 1 name:");

player1Name=scan.next();

//to skip next line

scan.nextLine();

System.out.print("Enter player 2 name:");

player2Name=scan.next();

System.out.println(" LETS PLAY WORD WARS!!!");

//calling the method to print alphabets

printAlphabets();

//do while to input the word till word is equal to '???'

do

{

do {

System.out.print(" "+player1Name+" enter your word:");

player1Word=scan.next();

//if player 1 word is ??? then break the do-while loop,then print final output

if("???".equals(player1Word) || player1Word=="???")

{

display();

break;

}else

{

if(hasMissingLetter(player1Word)==true)

{

System.out.println("YOU ENTERED A WORD THAT CONTAINS A LETTER THAT IS USED OR IS NOT VALID.PLEASE ENTER ANOTHER WORD!");

}else

{

//if(player1Word.length()>player1Score)

player1Score=player1Score+player1Word.length();

//do-while until player is agree on word.

do

{

System.out.println("Enter (y) yes if both players agree on the word");

ch1=scan.next().charAt(0);

}while(ch1!='y');

}

}

}while(hasMissingLetter(player1Word)==true);

deletAlphabets(player1Word);

//calling the method to print alphabets

printAlphabets();

do

{

System.out.print(" "+player2Name+" enter your word:");

player2Word=scan.next();

//if player 2 word is ??? then break the do-while loop,then print final output

if("???".equals(player2Word))

{

// player2Score=0;

display();

break;

}else

{

if(hasMissingLetter(player2Word)==true)

{

System.out.println("YOU ENTERED A WORD THAT CONTAINS A LETTER THAT IS USED OR IS NOT VALID.PLEASE ENTER ANOTHER WORD!");

}else

{

//if(player2Word.length()>player2Score)

player2Score=player2Score+player2Word.length();

//do-while until player is agree on word.

do

{

System.out.println("Enter (y) yes if both players agree on the word");

ch2=scan.next().charAt(0);

}while(ch2!='y');

}

}

}while(hasMissingLetter(player2Word)==true);

deletAlphabets(player2Word);

//calling the method to print alphabets

printAlphabets();

}while(true);

}else

{

//else close the game

System.out.println("THE GAME IS CLOSED.THANK YOU FOR PLAYING WORD WARS!!!");

System.exit(1);

}

}while(selection==1);

scan.close();

}

//methods used in the program

public static void printAlphabets()

{

System.out.print("Alphabet letters left:");

for(int i=0;i<alphabets.length;i++)

{

System.out.print(alphabets[i]+" ");

}

}

public static void deletAlphabets(String word)

{

for(int i=0;i<word.length();i++)

{

if(word.charAt(i)==vowels[0] || word.charAt(i)==vowels[1] || word.charAt(i)==vowels[2]

|| word.charAt(i)==vowels[3] || word.charAt(i)==vowels[4])

{

continue;

}else

{

for(int j=0;j<alphabets.length;j++)

{

if(alphabets[j]==word.charAt(i))

{

missingLetters.add(alphabets[j]);

alphabets[j]=' ';

break;

}

//break;

}

}

}

}

public static boolean hasMissingLetter(String word)

{

boolean has=false;

for(int i=0;i<word.length();i++)

{

if(missingLetters.contains(word.charAt(i)))

{

has=true;

break;

}

}

return has;

}

public static void display()

{

//displaying the final outputs

if(player1Score>player2Score)

{

System.out.println("WINNER OF THE GAME IS:"+player1Name+" with a score of "+player1Score);

}else

{

System.out.println("WINNER OF THE GAME IS:"+player2Name+" with a score of "+player2Score);

}

System.out.println("YOUR NAME HAS BEEN SAVED TO THE HALL OF FAME!!!");

System.out.println("THE GAME IS NOW OVER.THANK YOU FOR PLAYING WORD WARS!!!");

main(null);

}

}

Output:

Welcome to the WORD WARS game.

Press (1) To start the game.

Press any other key to exit the game.
Enter your selection:1
***************************************
Enter player 1 name:Andile
Enter player 2 name:Sam


LETS PLAY WORD WARS!!!
Alphabet letters left:a b c d e f g h i j k l m n o p r s t u v w x y z
Andile enter your word:java
Enter (y) yes if both players agree on the word
y
Alphabet letters left:a b c d e f g h i k l m n o p r s t u w x y z
Sam enter your word:logic
Enter (y) yes if both players agree on the word
y
Alphabet letters left:a b d e f h i k m n o p r s t u w x y z
Andile enter your word:concatenation
YOU ENTERED A WORD THAT CONTAINS A LETTER THAT IS USED OR IS NOT VALID.PLEASE ENTER ANOTHER WORD!

Andile enter your word:???
WINNER OF THE GAME IS:Sam with a score of 5
YOUR NAME HAS BEEN SAVED TO THE HALL OF FAME!!!
THE GAME IS NOW OVER.THANK YOU FOR PLAYING WORD WARS!!!


Welcome to the WORD WARS game.

Press (1) To start the game.

Press any other key to exit the game.
Enter your selection:0
***************************************
THE GAME IS CLOSED.THANK YOU FOR PLAYING WORD WARS!!!

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