Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)
import java.util.ArrayList;
public class PhaseOneTester
{
public static void main(String [] args) {
Dictionary dict = new
Dictionary("/Users/swapnil/IdeaProjects/BoggleGame/src/Dictionary.txt");
ArrayList<Tile>
tiles = new ArrayList<Tile>();
tiles.add(new
Tile('d',0,0));
tiles.add(new
Tile('o',0,1));
tiles.add(new
Tile('g',0,2));
Word w;
w = new
Word(tiles);
if
(dict.isValidWord(tiles))
{
System.out.printf("%s is a valid word\n",w);
System.out.printf("it is worth %d points\n",w.getPoints()); }
else
System.out.printf("%s is not a valid word\n",w);
tiles.clear(); //
start over
tiles.add(new
Tile("qu",0,0));
tiles.add(new
Tile('i',0,1));
tiles.add(new
Tile('e',0,2));
tiles.add(new
Tile('t',0,3));
w = new
Word(tiles);
if
(dict.isValidWord(tiles))
{
System.out.printf("%s is a valid word\n",w);
System.out.printf("it is worth %d points\n",w.getPoints()); }
else
System.out.printf("%s is not a valid word\n",w);
tiles.clear(); //
start over
tiles.add(new
Tile('p',0,0));
tiles.add(new
Tile('l',0,1));
tiles.add(new
Tile('e',0,2));
tiles.add(new
Tile('a',0,3));
tiles.add(new
Tile('s',1,3));
tiles.add(new
Tile('e',1,2));
w = new
Word(tiles);
if
(dict.isValidWord(tiles))
{
System.out.printf("%s is a valid word\n",w);
System.out.printf("it is worth %d points\n",w.getPoints()); }
else
System.out.printf("%s is not a valid word\n",w);
Board board = new
Board();
System.out.println(board);
} }
------------------------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class Board {
private static final int DICE_SIDES = 6;
private ArrayList<String> dice = new
ArrayList<>(Arrays.asList("RIFOBX","IFEHEY","DENOWS","UTOKND","HMSRAO","LUPETS",
"ACITOA","YLGKUE","QBMJOA","EHISPN","VETIGN","BALIYT","EZAVND","RALESC","UWILRG","PACEMD"));
private ArrayList<Tile> row1 = new
ArrayList<>();
private ArrayList<Tile> row2 = new
ArrayList<>();
private ArrayList<Tile> row3 = new
ArrayList<>();
private ArrayList<Tile> row4 = new
ArrayList<>();
private ArrayList<ArrayList<Tile>>
rows = new
ArrayList<>(Arrays.asList(row1,row2,row3,row4));
public Board()
{
Random rand = new
Random();
while (dice.size() >
0)
{
for (int i = 0; i < rows.size();i++)
{
for (int j = 0; j < rows.size();j++)
{
int diceNum = rand.nextInt(dice.size());
String diceLetter =
String.valueOf(dice.get(diceNum).charAt(rand.nextInt(DICE_SIDES)));
Tile t = new Tile(diceLetter,i,j);
rows.get(i).add(t);
dice.remove(diceNum);
}
}
}
}
public ArrayList<Tile> getRow1()
{
return row1;
}
public ArrayList<Tile> getRow2() {
return row2;
}
public ArrayList<Tile> getRow3() {
return row3;
}
public ArrayList<Tile> getRow4() {
return row4;
}
public ArrayList<ArrayList<Tile>>
getRows() {
return rows;
}
@Override
public String toString()
{
StringBuilder
stringBuilder = new StringBuilder();
stringBuilder.append("
_0__1__2__3_\n");
for (int i = 0;i <
rows.size();i++)
{
stringBuilder.append(i+"| ");
for (int j = 0; j < rows.size(); j++)
{
String s = rows.get(i).get(j).getLetterShowing();
if (s.equals("Q")||s.equals("QU"))
{
stringBuilder.append("Qu ");
rows.get(i).get(j).setLetterShowing("Qu");
}
else {
stringBuilder.append(s+ " ");
}
}
stringBuilder.append("\n");
}
return
stringBuilder.toString();
}
}
------------------------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
public class Word {
private String word;
private int points;
public Word(ArrayList<Tile>
entry)
{
StringBuilder sb = new
StringBuilder();
for (int i = 0; i <
entry.size();i++)
{
sb.append(entry.get(i).getLetterShowing());
}
word = sb.toString();
int wordLength =
word.length();
if (wordLength <
3)
points = 0;
if (wordLength == 3 ||
wordLength == 4)
points = 1;
if (wordLength ==
5)
points = 2;
if (wordLength ==
6)
points = 3;
if (wordLength ==
7)
points = 5;
if (wordLength >=
8)
points = 11;
}
public int getPoints()
{
return points;
}
@Override
public String toString()
{
return
(word.toUpperCase());
}
}
------------------------------------------------------------------------------------------------------------------------------------
public class Tile {
private String letterShowing;
private int row;
private int column;
private boolean tileUsed;
public Tile(String letter, int row, int
column)
{
letterShowing =
letter;
this.row = row;
this.column =
column;
tileUsed = false;
}
public Tile(char letter, int row, int
column)
{
letterShowing =
String.valueOf(letter);
this.row = row;
this.column =
column;
tileUsed = false;
}
public Tile(Tile tile)
{
letterShowing =
tile.getLetterShowing();
row =
tile.getRow();
column =
tile.getColumn();
tileUsed =
tile.getTileUsed();
}
public String getLetterShowing()
{
return
letterShowing;
}
public void setLetterShowing(String
qCase){
letterShowing =
qCase;
}
public int getRow(){
return row;
}
public int getColumn(){
return column;
}
public boolean getTileUsed()
{
return tileUsed;
}
public void setTileUsed(boolean tileUsed)
{
this.tileUsed =
tileUsed;
}
@Override
public String toString(){
if
(letterShowing.equals("Q") || letterShowing.equals("q")){
letterShowing = "QU";
}
return
letterShowing;
}
}
------------------------------------------------------------------------------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Dictionary{
private ArrayList<String> dict;
public Dictionary(String fileName)
{
try {
Scanner inFile = new Scanner(new File(fileName));
dict = new ArrayList<>();
while (inFile.hasNext()) {
dict.add(inFile.next());
}
inFile.close();
}catch (IOException
e){
System.out.println("Dictionary file not found.");
}
}
public boolean isValidWord(ArrayList<Tile>
tiles)
{
Word w = new
Word(tiles);
return
dict.contains(w.toString());
}
public boolean isValidWord(Word word){
return
dict.contains(word.toString().toLowerCase());
}
}
60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictio...
Question 2: Finding the best Scrabble word with Recursion using java Scrabble is a game in which players construct words from random letters, building on words already played. Each letter has an associated point value and the aim is to collect more points than your opponent. Please see https: //en.wikipedia.org/wiki/Scrabble for an overview if you are unfamiliar with the game. You will write a program that allows a user to enter 7 letters (representing the letter tiles they hold), plus...
This task involves constructing a Java program that supports interaction via a graphical user interface.The object is to implement a Scrabble graphical game. The basis for the game is quite simple. Presented with a 6x6 grid of Scrabble tiles, the challenge is for the player(s) to form as many high scoring words as possible. Words may only be formed from sequences of adjacent tiles. Two tiles are adjacent if their edges or corners meet. A tile may...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...
Ch 04: Mastery Assignment - Introduction to Probability 4. Scrabble SCRABBLE is a word game in which two to four players score points by forming words from individual lettered tiles on a game board marked with a 15 by 15 grd. The words are formed across and down in crossword puzzle fashion and must appear in a standard dictionary. There are 100 tiles in all, including 2 blank tiles that serve as wild cards and can take on the value...
Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public class WordGame { /* * Returns all strings that appear * as a consecutive horizontal or vertical sequence of letters * (left-right, right-left, up-down, or down-up) * in the array board and also appear in dict. * Note that the same word may appear multiple times * on the board, and will then be multiple times in * the returned array. * * dict is assumed to be...
1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...
I've previously completed a Java assignment where I wrote a program that reads a given text file and creates an index that stores the line numbers for where individual words occur. I've been given a new assignment where I need to modify some of my old code. I need to replace the indexer in my Index class with a NavigableMap<String, Word> and update my Word class with NavigableSet<Integer> lines. The instantiated objects should be TreeMap() and TreeSet(). I have below...
Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This class is used by: * 1. FindSpacing.java * 2. FindSpacingDriver.java * 3. WordGame.java * 4. WordGameDriver.java */ public class WordGameHelperClass { /* * Returns true if an only the string s * is equal to one of the strings in dict. * Assumes dict is in alphabetical order. */ public static boolean inDictionary(String [] dict, String s) { // TODO Implement using binary search...
CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...