Question

I'm trying to figure out how to create a class ScrabbleGame.java that contains the two following...

I'm trying to figure out how to create a class ScrabbleGame.java that contains the two following methods:

The first method, SpelledIT, consists of the two strings StringTile and StringWord and determines whether tiles set can spell the word, returning true if so & false otherwise.

The second, doubloon, takes a string and checks whether it is a doubloon. Use the toLowerCase method before checking to ignore case.

Please use nested loops not arrays.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
* @author Chegg
*
*/
public class ScrabbleGame {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       // Some Example to Test Method
       System.out.println(SpelledIT("cenimatography","minato"));
       System.out.println(doubloon("abba"));
       System.out.println(doubloon("Shanghaiingss"));


   }
  
   public static boolean SpelledIT(String StringTile, String StringWord) {
       for(int i=0;i<StringWord.length();i++) {
   if(StringTile.indexOf(StringWord.charAt(i)) == -1) {
   return false;
   } else {
   int charLocation = StringTile.indexOf(StringWord.charAt(i));
   StringTile = StringTile.substring(0,charLocation)
   + StringTile.substring(charLocation+1,StringTile.length());
   }
   }

   return true;
   }

  
   public static boolean doubloon(String checkDoubloon) {
      
       String lowerCheckDoubloon=checkDoubloon.toLowerCase();
       boolean check = true;

       for(int i= 0; i<lowerCheckDoubloon.length();i++){
       int count=0;
       for(int j=0;j<lowerCheckDoubloon.length();j++){
       if(lowerCheckDoubloon.charAt(i)==lowerCheckDoubloon.charAt(j)) count++;
       }
       if (count != 2) {
       check = false;
       break;
       }
       }

   return check;
   }
}

Add a comment
Know the answer?
Add Answer to:
I'm trying to figure out how to create a class ScrabbleGame.java that contains the two following...
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
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