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.

Can you paste us the error messages you get?

The error just says uncompilable source code.

The error lines appear on lines 9 and 13 in LetterHist.java and on line 85 in Main.java

char ch = ''; //Not a valid char
char ch = ' '; //A valid char
System.out.println("blah" + ch + "blah");

The error just says uncompilable source code.

The error lines appear on lines 9 and 13 in LetterHist.java and on line 85 in Main.java

No, the compiler does not just say "Uncompilable source code". There is an explicit reason given and you should take the time to read it.

There is only one error line appear now which is in main.java and it is on line 85. The error says that it cannot find symbol for letterHist.

I have fixed the code. Now the real question that I want solve is:

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.

How should I solve this?

Your teacher's suggestion is incomplete.

Either your teacher is trying to get you to
A. Describe an algorithm for figuring out the best possible letter, and placement, of the blank tile (such that it maximizes the point value of the word)
B. Describe an algorithm for figuring out the best possible letter that should be on a blank tile, given its placement.

Which is it? Either way I'm not writing any pseudocode for you, you can do that yourself. Just saying.

Well like [[my program that I'm blatantly violating the rules promoting here]] there are blanks/wildcards. So if you don't want blanks then its first a database call.Its easier to query with the NOT keyword that only words with the users letters are returned. You just need to get the database call correct and then return that list to the user. Yes the database query is pretty long but a good database can handle it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.