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

  • For this assignment you will create a one-player variation of the game BlackJack. The game will...

    For this assignment you will create a one-player variation of the game BlackJack. The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game...

  • The project in C is to create a game in which a player goes through a...

    The project in C is to create a game in which a player goes through a series of rooms in which they can find a prize or a monster to fight. Game Rules: • A player will enter the number of rooms (greater than 1) they want to endure. The program will dynamically allocate an array of Rooms and populate it with prizes and monsters. Then, the player will enter each room in which an action will occur: o If...

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

  • WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...

    WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot. Pig Dice Game Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount...

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

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