Main.java
package scrabble;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
public class Main {
public static boolean isDoubloon (String word) {
int count[] = LetterHist.letterHist (word);
for (int i = 0; i < count.length; i++)
if (count[i] == 2 || count[i] == 0)
continue;
else
return false;
return true;
}
public static void haveFunWithJOptionPane () {
JDialog.setDefaultLookAndFeelDecorated(true);
int response = JOptionPane.showConfirmDialog(null,
"Do you want to test a word?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.NO_OPTION)
{
System.out.println("No button clicked");
} else
if (response == JOptionPane.YES_OPTION)
{
System.out.println("Yes button clicked");
String testWord = JOptionPane.showInputDialog("Enter the test word:");
String tiles = JOptionPane.showInputDialog(null,
"Enter the tiles (use * for wildcard:",
"Scrabble Tiles", JOptionPane.PLAIN_MESSAGE);
boolean result = testWord ( testWord, tiles);
String msg = "The word " + testWord;
if (result == true)
msg+= " can be made with the tiles";
else
msg+= " cannot be made with the tiles";
JOptionPane.showMessageDialog(null, msg, "The Results!",
JOptionPane.INFORMATION_MESSAGE);
response = JOptionPane.showConfirmDialog(null, "Was this fun, or what??");
System.out.println (result);
}
else if (response == JOptionPane.CLOSED_OPTION)
{
System.out.println("JOptionPane closed");
}
}
public static boolean testWord (String tiles, String words) {
int[] tilesCount = LetterHist.letterHist (tiles);
int[] wordCount = LetterHist.letterHist (words);
for (int i = 0; i < wordCount.length; i++) {
if (wordCount[i] <= tilesCount[i])
continue;
else
return false;
}
return true;
}
public static boolean testWordModify (String tiles, String words) {
int[] tilesCount = LetterHist.letterHist (tiles);
int[] wordCount = LetterHist.letterHist (words);
int falseCount = 0;
for (int i = 0; i < wordCount.length; i++) {
if (wordCount[i] <= tilesCount[i])
continue;
else
falseCount++;
}
if (falseCount <= tilesCount[26])
return true;
else
return false;
}
public static void main(String[] args) {
// TODO code application logic here
int count[] = letterHist ("afayafkhkFFGhjk");
for (int i = 0; i < count.length; i++)
System.out.println (count[i]);
System.out.println (isDoubloon ("alalsxxsx"));
haveFunWithJOptionPane ();
System.out.println (testWordModify ("qijbo", "jjib"));
}
}
LetterHist.java
package scrabble;
public class LetterHist {
public static int[] letterHist (String cal) {
int[] counts = new int[27];
char[] chart = cal.toCharArray ();
for (int i = 0; i < chart.length; i++) {
if (chart[i] == '') { //tiles are represented by blank spaces
counts[26]++;
continue;
}
chart[i] = Character.toLowerCase (chart[i]);
counts[chart[i] - 97]++;
}
return counts;
}
}
Can you please help me with:
(a) There are error lines that appear in the code above. Can you please tell me how to fix it?
(b) After fixing this code, I want to do the following:
In real Scrabble, there are some blank tiles that can be used as
wild cards; that is, a blank tile can be used to represent any letter.
Think of an algorithm for testWord that deals with wild cards. Just describe the algorithm, using English, pseudocode, or Java.