*Here are the provided classes*: TestGame.java import java.io.*; import java.io.File; // Import the File class import j

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

*Here are the provided classes*: TestGame.java import java.io.*; import java.io.File; // Import the File class import j

Post by answerhappygod »

Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 1
Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 1 (157.73 KiB) Viewed 9 times
Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 2
Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 2 (153.53 KiB) Viewed 9 times
Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 3
Here Are The Provided Classes Testgame Java Import Java Io Import Java Io File Import The File Class Import J 3 (119.08 KiB) Viewed 9 times
*Here are the provided classes*:
TestGame.java
import java.io.*;import java.io.File; // Import the File classimport java.util.ArrayList;import java.util.Arrays;import java.util.Scanner; // Import the Scanner class to read textfiles
public class TestGame {
public static void main(String[] args) throwsException{ //All required variables tostore tests' results if you want to do that /**************************************************/ BufferedWriter writer = newBufferedWriter(new FileWriter("tests_results_game.txt")); File myObj=null; Scanner scanRead=null; /**************************************************/ Scrabble game1, game2, game3,game4, game5; Tile[] gameTwoTiles = newTile[7]; Tile[] gameThreeTiles = newTile[7]; Tile[] gameFourTiles = newTile[7]; Tile[] gameFiveTiles = newTile[7]; gameTwoTiles[0] = newTile('A'); gameTwoTiles[1] = newTile('B'); gameTwoTiles[2] = newTile('C'); gameTwoTiles[3] = newTile('D'); gameTwoTiles[4] = newTile('E'); gameTwoTiles[5] = newTile('F'); gameTwoTiles[6] = newTile('G'); gameThreeTiles[0] = newTile('Z'); gameThreeTiles[1] = newTile('Y'); gameThreeTiles[2] = newTile('X'); gameThreeTiles[3] = newTile('W'); gameThreeTiles[4] = newTile('V'); gameThreeTiles[5] = newTile('U'); gameThreeTiles[6] = newTile('T'); gameFourTiles[0] = newTile('Y'); gameFourTiles[1] = newTile('Z'); gameFourTiles[2] = newTile('T'); gameFourTiles[3] = newTile('W'); gameFourTiles[4] = newTile('U'); gameFourTiles[5] = newTile('V'); gameFourTiles[6] = newTile('X'); gameFiveTiles[0] = newTile('C'); gameFiveTiles[1] = newTile('O'); gameFiveTiles[2] = newTile('O'); gameFiveTiles[3] = newTile('O'); gameFiveTiles[4] = newTile('L'); gameFiveTiles[5] = newTile('Y'); gameFiveTiles[6] = newTile('Y'); game1 = new Scrabble(); game2 = newScrabble(gameTwoTiles); game3 = newScrabble(gameThreeTiles); game4 = newScrabble(gameFourTiles); game5 = newScrabble(gameFiveTiles); ArrayList<String>getWordCheckerGameThree = new ArrayList<String>() {{ add("TUX"); add("UT"); add("WUZ"); add("XU"); add("YU"); add("YUTZ"); }}; ArrayList<String>getWordCheckerGameFive = new ArrayList<String>() {{ add("CLOY"); add("CLY"); add("COL"); add("COLY"); add("COO"); add("COOL"); add("COOLY"); add("COY"); add("COYLY"); add("LO"); add("LOCO"); add("LOO"); add("LOY"); add("OO"); add("OY"); add("YO"); }}; // Test 1 - constructors andgetLetters if(game2.getLetters().equals("ABCDEFG")) { System.out.println("Test 1 Passed"); writer.write("test 1 passed \n"); } else { System.out.println("Test 1 Failed"); writer.write("test 1 failed \n"); } // Test 2 - constructors andgetLetters if(game3.getLetters().equals("ZYXWVUT")) { System.out.println("Test 2 Passed"); writer.write("test 2 passed \n"); } else { System.out.println("Test 2 Failed"); writer.write("test 2 failed \n"); } // Test 3 - equals if (game3.equals(game4)){ System.out.println("Test 3 Passed"); writer.write("test 3 passed \n"); } else { System.out.println("Test 3 Failed"); writer.write("test 3 failed \n"); } //Test 4 - equals if (game3.equals(game1)){ System.out.println("Test 4 Failed"); writer.write("test 4 Failed \n"); } else { System.out.println("Test 4 Passed"); writer.write("test 4 Passed \n"); } // Test 5 - getWords
if(game3.getWords().equals(getWordCheckerGameThree)) { System.out.println("Test 5 Passed"); writer.write("test 5 passed \n"); } else { System.out.println("Test 5 Failed"); writer.write("test 5 failed \n"); } // Test 6 - getWords
if(game5.getWords().equals(getWordCheckerGameFive)) { System.out.println("Test 6 Passed"); writer.write("test 6 passed \n"); } else { System.out.println("Test 6 Failed"); writer.write("test 6 failed \n"); } // Test 7 - getScores int[] vals = {2, 5, 9, 10,15, 16};
if(Arrays.toString(game3.getScores()).replaceAll("\\s+","").equals(Arrays.toString(vals).replaceAll("\\s+",""))){ System.out.println("Test 7 Passed"); writer.write("test 7 passed \n"); } else { System.out.println("Test 7 Failed"); writer.write("test 7 failed \n"); }
// Test 8 -getScores int[] vals2 = {2, 2, 3, 3, 3,3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 11, 11};
if(Arrays.toString(game2.getScores()).replaceAll("\\s+","").equals(Arrays.toString(vals2).replaceAll("\\s+",""))){ System.out.println("Test 8 Passed"); writer.write("test 8 passed \n"); } else { System.out.println("Test 8 Failed"); writer.write("test 8 failed \n"); }
writer.close(); }}
In this assignment, you are provided with a text file consisting of all 279,496 words published in the 2019 version of the Collins Scrabble Word dictionary. Given the letters of seven randomized Scrabble tiles, you must determine the set of scores that a player could possibly obtain by placing these tiles. We will be assuming three traits that differ slightly from the traditional game of Scrabble: 1. There is an unlimited amount of every letter within the scrabble bag, thus it is reasonable to assume (though incredibly unlikely) that you could obtain something like ['A', 'A', 'A', 'A', 'A', 'A', 'A']. 2. You will be placing these tiles during the first turn on the board. Thus, you do not need to worry about combining your word with any pre-existing letters that might have already been placed on the Scrabble board. 3. Assume that there exist no word or letter bonuses. We will simply be basing the score off the tile values. As an example, assume that your seven randomized tiles read: {'A', 'C', 'A', 'A', 'B', 'A', 'H'} The output should be 1) a list of length n of words that can be created using these letters, and 2) a list of length n containing the scores (integers) for each of the words of length 1 ≤ m ≤7 that can be created using these letters (like 'AA', or 'AAH', which are both words within the Collins Scrabble Word dictionary, surprisingly). So two of the scores that will be in your score set for the above tile set are 2 (A (1) + A (1) = 2), and 6 (A (1) + A (1) + H (4) = 6). Provided Files The following is a list of files provided to you for this assignment. Do NOT alter these files. CollinsScrabble Words2019.txt TestGame.java
Scrabble.java This class represents the Scrabble game in which there are seven randomly selected tiles, and scoring is performed for each possible word (this will be the tougher class to implement). The class must have the following private variables: • tiles (Tile[]) The class must have the following public methods: • public Scrabble() [constructor] o Initialize the Tile array and 'pickup' for random values • public Scrabble(Tile []) [constructor] o Initialize the tile array with the given argument • public String getLetters() o Return a string that is all of the tile characters (for example, "ABFEODL") • public ArrayList<String> getWords() o Create an ArrayList of Strings with n elements. Each element should represent a word that can be created using the current tiles. The algorithm for this method should reference the provided file CollinsScrabble Words2019.txt ** do NOT put this file somewhere on your local machine and hardcode the local directory. This will likely cause your tests to fail on GradeScope. Also, do not put it within a folder in the relative path. • public int[] getScores() o Create an int array with n elements. Each element in this list should represent each individual score for each word that can be created using the current tiles. This should be returned in ascending order. • public Boolean equals(Scrabble) o Compare the given Scrabble object from the argument with the 'this' object to see if they are equal (do they have the same tiles?).
Classes to Implement For this assignment, you must implement two java classes: Tile and Scrabble. Follow the guidelines for each one below. In these classes, you can implement more private (helper) methods if you want to. You may not, however implement more public methods. You may not add instance variables other than the ones specified below nor change the variable types or accessibility (i.e. making a variable public when it should be private). Penalties will be applied if you implement additional instance variables or change the variable types of modifiers from what is described here. Tile.java This class represents a single Scrabble tile that will be used in the game. The class must have the following private variables: • value (char) The class must have the following public methods: • public Tile() [constructor] o Initialize value to " • public Tile(char) [constructor] o Initialize value to the given argument • public void pickup() o Generate a random character between A and Z (inclusive) and set the value to that letter. o Feel free to use 'java.util.random' for this method • public char getValue() o Returns the tile value
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply