Question

60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictionary.txt) required to run yoDictionary class -The dictionary is an ArrayList of Strings containing the words from the dictionary. The sole constructor wiimport java.util.ArrayList; public class PhaseOneTester public static void main (String[ args) Dictionary dict-new Dictionary

60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictionary.txt) required to run your program Background Boggle is a word game using a plastic grid of lettered dice, in which players attempt to find words in sequences of adjacent letters. The dice are randomly arranged in the grid, and players have 90 seconds to form as many words as possible from adjacent top-facing letters For example, the word SUPER is spelled in the gameboard to the right. Letters are considered adjacent if they are next to each other in a row column, or diagonally DİGIHI 1 KLPS Each word has a score and a player's score is the sum of all the scores for each word they found. The minimum word size to count is 3-letters. Scoring is as follows EORIN Size of word 3 4 Points 2 3 6 7 8 or more The same letter can't be used twice in the same word (unless it appears again on a different die) A word is considered valid if it's found in an English dictionary. You will be supplied with a text file of dictionary words to use as a reference ImplementationPhase I We will be implementing this game in three phases. Each phase is dependent on the prior phase, so it is imperative that you do not fall behind.! We will be implementing a solitaire version. For this first phase, you will implement the following classes Tile class - represents one tile on the board. It stores the letter showing, the row and column where it is located on the board, and a flag to indicate if the tile has been selected by the player Word class - represents a word that was entered by a player. It stores the characters in the word (I chose to put them in a String), as well as the points the word is worth. It should have one constructor that takes an Arraylist of Tile objects
Dictionary class -The dictionary is an ArrayList of Strings containing the words from the dictionary. The sole constructor will take a string representing a filename and load the ArrayList from the provided file. Include a method, isValidWord, that takes an ArrayList of Tile objects and returns a boolean value indicating if the word formed by the letters on the tiles (in order) is a valid word Board class - represents the playing board and the letters showing on the board. Each row is an ArrayList of tile objects, and the entire board is an ArrayList of rows. Thus this contains an ArrayList of ArrayLists of Tile objects When you construct your board, first make a list of 16 dice, as follows (I used an ArrayList of Strings The DIE0 : R, 1, F, О, В, Х DIE1: I, F, E, H, E, Y DIE2: D, E, N, o, W, S D1 E 3 : U, T, O, K, N, D D1E4 : H, M, s, R, A, o DIE5: L, U, P, E, T, S DIE6: A, C, I, T, o, A DIE7: Y, L, G, K, U, E DIE8: Qu, B, M, J, O, A DIE9: E, H, I, S, P, N DIE10 V, E, T, I, G, N DIE11: B, A, L, I, Y, T DIE12: E, Z, A, V, N, D DIE13: R, A, L, E, S, C DIE14: U, W, I, L, R, G DIE15: P, A, C, E, M, D Construct your empty board (the ArrayList of ArrayLists). Randomly select one die. Randomly select one of its 6 sides. Create a Tile with that character and place it in the board. Fill the board systematically (location 0,0 then 0,1 etc) so you know the Tile row and column when creating the Tile Note: The Qu is a special case where 1 die side has 2 letters. How will you handle this special case when storing the letteґ on the Tile? How will you handle it when displaying the board to the letters remain lined up if a Qu appears? You will find a short driver on the next page. This is meant to get you started, it does not test all functionality that is required For all classes, be sure to consider the following: What constructor(s) should be available? Which instance variables should a client be able to change? (getters/setters) Does a toString make sense? Will you ever need to compare 2 of the object type? (.equals) Be sure your equals is a true override (use the @Override annotation) These are decisions for you to make (and defend), even if there is no specific requirement listed.
import java.util.ArrayList; public class PhaseOneTester public static void main (String[ args) Dictionary dict-new Dictionary ("dictionary.txt") ArrayList tiles = new ArrayList(); // experiment with dǐ fferent words here to be sure the isvalidWord // method (below)is working. /7 NOTE owhere are you testing the location/adjancency of // tiles. this will be done in the Game class, Phase 2 tiles.add (new Tile ('d',0,0)) tiles.add (new Tile ('o,0,1)); tiles.add (new Tile ('g',0,2)) Word w; wnew Word (tiles) if (dict.isValidWord (tiles)) System.out.printf("%s System.out.printf("it is is a valid word\n", w); worth %d points\n", w.getPoints()); else System.out.printf("%s is not a valid word \n".w); tiles.clear I/ start over tiles.add (new Tile("qu",0,0)) tiles.add (new Tile('i',0,1)); tiles.add (new Tİle ('e',0,2)); tiles.add (new Tile ('t',0,3)) wnew Word (tiles) if (dict.isValidword(tiles)) System.out.printf("%s System.out.printf("it is a valid word\n", w); 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);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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());
    }


}


BoggleGame [-/ldeaProjects/BoggleGame - ..src/PhaseOneTester.java [BoggleGame] BoggleGame src PhaseOneTester Project ▼ *÷ *-a

Add a comment
Know the answer?
Add Answer to:
60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictio...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2: Finding the best Scrabble word with Recursion using java Scrabble is a game in...

    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...

    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...

    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:...

    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...

    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 c...

    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,...

    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...

    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...

    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 fil...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT