Question

Function name: crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int...

Function name: crazy_scrabble

Parameters : word (string), current points (int), double word score (boolean)

Returns: int

Description: You are playing scrabble with a friend, and you thought you knew how to

calculate how many points you have, but your friend suddenly starts making up all these

crazy rules. Write a function that helps keep track of how many points you have with

these new rules:

●Each 'k', 'm', 'p', 'x', 'y', and 'z' earns you 7 points.

●'c' and 's' are worth 4 points each.

●Each vowel ('a','e','i','o','u') you causes you to lose 2 points.

●All other letters are worth 1 point.

●Each time a letter is reused in a word, the player loses 1 point.

●If your word is more than 6 letters long, you get a bonus of 3 points.

●If the double word score is True and the point total for the word is positive ( > 0), the player receives double the points for the word.

The function should return the player’s new point total. Assume that the words will not

be empty strings and will only consist of lowercase letters from a to z.

Note:

​A player cannot have an overall negative point total. Return 0 if the point total

would be negative after the new word the player has played. For example, if a player

currently has 7 points but would lose 9 points from their new word, the player should

have 0 points now, not -2 points.

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

Thanks for posting the question, we are glad to help you. Here is the complete function that computes the score of a word based on the given rules. All the rules are taken into consideration and commented out in the method

Here is the code

_________________________________________________x_______________________________________________

import java.util.HashSet;
import java.util.Set;

public class ScrabbleWordCalculator {

   public static void main(String[] arg) {
      
       System.out.println("Score: "+crazy_scrabble("house", 0, false));

   }
  
   //Function name: crazy_scrabble
   //Parameters : word (string), current points (int), double word score (boolean)
   //Returns: int
  
   public static int crazy_scrabble(String word, int currentPoints, boolean doubleWordScore) {

      
       word = word.toLowerCase();
       // If your word is more than 6 letters long, you get a bonus of 3 points.
       currentPoints += word.length() > 6 ? 3 : 0;

       // we are using a HashSet to store the characters and see if its repeating
       Set<Character> characters = new HashSet<>(26);

       for (char letter : word.toCharArray()) {

           //// we are using a HashSet to store the characters and see if its repeating
           if (characters.contains(letter)) {
               // Each time a letter is reused in a word, the player loses 1 point.
               currentPoints -= 1;

           } else {
               // Each 'k', 'm', 'p', 'x', 'y', and 'z' earns you 7 points.
               if (letter == 'k' || letter == 'm' || letter == 'p' || letter == 'x' || letter == 'y'
                       || letter == 'z') {
                   currentPoints += 7;

                   // 'c' and 's' are worth 4 points each.
               } else if (letter == 'c' || letter == 's') {
                   currentPoints += 2;

                   // Each vowel ('a','e','i','o','u') you causes you to lose 2 points.
               } else if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') {

                   currentPoints -= 2;

               } else {
                   // All other letters are worth 1 point.
                   currentPoints += 1;

               }

           }
           characters.add(letter);

       }

       // ​A player cannot have an overall negative point total.
       currentPoints = currentPoints < 0 ? 0 : currentPoints;
       // If the double word score is True and the point total for the word is positive
       return doubleWordScore ? 2 * currentPoints : currentPoints;

   }

}

_________________________________________________x_______________________________________________

Add a comment
Know the answer?
Add Answer to:
Function name: crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int...
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
  • Use PYTHON!!! NOT Java or anything else!! Function name : crazy_scrabble Parameters : word (string), current...

    Use PYTHON!!! NOT Java or anything else!! Function name : crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int Description : You are playing scrabble with a friend, and you thought you knew how to calculate how many points you have, but your friend suddenly starts making up all these crazy rules. Write a function that helps keep track of how many points you have with these new rules: ● Each 'k', 'm', 'p', 'x',...

  • Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description:...

    Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

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

  • MATLAB code help! Function Name: chemTimer Inputs: 1. (double) The current position of the hour hand 2. (double) The current position of the minute hand 3. (double) A positive or negative number of m...

    MATLAB code help! Function Name: chemTimer Inputs: 1. (double) The current position of the hour hand 2. (double) The current position of the minute hand 3. (double) A positive or negative number of minutes Outputs: 1. (double) The position of the hour hand after the specified time 2. (double) The position of the minute hand after the specified time Background: Oh no, you were running late to your Chem lab and completely forgot your reaction timer! It's a good thing...

  • First, you will need to create the Creature class. Creatures have 2 member variables: a name,...

    First, you will need to create the Creature class. Creatures have 2 member variables: a name, and the number of gold coins that they are carrying. Write a constructor, getter functions for each member, and 2 other functions: - void addGoldCoins(int) adds gold coins to the Creature. - void identify() prints the Creature information. The following should run in main: Creature d{"dragon", 50}; d.addGoldCoins(10); d.identify(); // This prints: The dragon is carrying 60 gold coins. Second, you are going to...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • 60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictio...

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

  • Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...

    Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define a constructor with default values to initialize strings to NULL, unit to 0 and gpa to 0.0. Define a copy constructor to initialize class members to those of another Student passed to it as parameters. Overload the assignment operator (=) to assign one Student to another. Define a member function called read() for reading Student data from the user and a function called print()...

  • C++ help Format any numerical decimal values with 2 digits after the decimal point. Problem descr...

    C++ help Format any numerical decimal values with 2 digits after the decimal point. Problem description Write the following functions as prototyped below. Do not alter the function signatures. /// Returns a copy of the string with its first character capitalized and the rest lowercased. /// @example capitalize("hELLO wORLD") returns "Hello world" std::string capitalize(const std::string& str); /// Returns a copy of the string centered in a string of length 'width'. /// Padding is done using the specified 'fillchar' (default is...

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