Question

please help Create a program that prompts the user for a sentence and then displays the...

please help

Create a program that prompts the user for a sentence and then displays the hash of the sentence. Refer to the textbook Chapter 5.2 and the Support Video in zyBook section 3.1 for more instruction on hashing.

Program Requirements:

The program should prompt the user for the "sentence" to be hashed and then compute the hash of the sentence by summing the numeric value of each letter in the sentence (use A=a=1, B=b=2 ... Z=z=26, space=31) and applying the hash function f(n) = sum mod 31.  Repeat the prompt and computation until the user enters a sentinel value to quit.

For example:

If the user enters: the hash is:
hello 21
pooh bear 18
We the People of the United States in Order to form a more perfect Union 27
  • The sentence may be as small as a single word or contain multiple words
  • The sentence can contain upper case and lower case letter but no numbers or symbols.
  • Provide some test cases <test values> I should key in along with the expected outcome of the provided values. Review the Developing Test Cases document in the Getting Started module for some examples of how to create/format test cases.
  • Don't use my examples as your test cases...
0 0
Add a comment Improve this question Transcribed image text
Answer #1

==================================

import java.util.*;

public class Main {

public static void main(String[] args) {


int sum = 0;

Scanner sc = new Scanner(System.in);

System.out.print("Enter data or (quit) to stop: ");

String str;

str = sc.nextLine();

while(!str.equals("quit")){

sum = 0;

str = str.toLowerCase();

for(int i=0 ; i<str.length(); ++i){



if(str.charAt(i)==' ')

sum = sum + 31;

else

sum = sum + (str.charAt(i) - 'a' ) + 1;

}

System.out.println(sum%31);

System.out.print("Enter data or (quit) to stop: ");

str = sc.nextLine();

}

System.out.print("\n......Exiting.......");


}

}

========================================================================

Add a comment
Know the answer?
Add Answer to:
please help Create a program that prompts the user for a sentence and then displays the...
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
  • IN JAVA 1. Create a program that prompts the user for an integer and then displays...

    IN JAVA 1. Create a program that prompts the user for an integer and then displays a message indicating whether or not the number is a perfect square. This can be determined by finding the square root of a number, truncating it (by casting the double result), and then squaring that result 2. Write a program that prompts the user for two numbers. The first number is a minimum value and the second number is a maximum value. RandomNum then...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Create a java program MyGrader that prompts the user for a series of grades between 0...

    Create a java program MyGrader that prompts the user for a series of grades between 0 .. 100. A -1 grade is the end of input sentinel. There can be a maximum of 100 grades. find sum and average and standard deviation (USe arrays and loops for solving this problem)

  • Write a program that prompts the user to input daily rainfalls and display the total and...

    Write a program that prompts the user to input daily rainfalls and display the total and average rainfall. Use a sentinel controlled loop with sentinel value of -1.   Your output values should only have three digits after the decimal point. Test your program with following input data. 0.31 0.0 0.52 0.79 1.15 1.23 0.93 0.0 0.0 -1 The output of the program should be: The total rainfall is : 4.930 The average rainfall is : 0.547 Copy and paste your...

  • Write a program that prompts the user to enter a file name and displays the occurrences...

    Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the file. Letters are case-insensitive. Here is a sample run: Enter a filename: Lincoln.txt Number of A’s: 23 Number of B’s: 0 Number of C’s: 12 …… Number of Y’s: 5 Number of Z’s: 7

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • in a java application need  to create an application which prompts the user numerator and denominator values...

    in a java application need  to create an application which prompts the user numerator and denominator values then show the result of the division.  The application will use exception handling to verify the user has entered valid input and will continue to prompt the user for input as long as the value they enter is invalid.  Once the user has entered valid numerator and denominator values, the result is shown and the application exits. had some issues when I entered letters instead of...

  • C# programming Create an application that prompts the user for a storm windspeed in mph, then...

    C# programming Create an application that prompts the user for a storm windspeed in mph, then determines the correct typhoon category. The program must run all test cases of storm windspeed in one execution. Use a sentinel value to terminate the program. Do not assume a specific number of inputs. Determine the maximum storm windspeed value input. Note that the maximum must be evaluated within your program. You MAY NOT use C built in function. Output screenshot must include the...

  • Write program that prompts the user to enter a person's date of birth in numeric form...

    Write program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle...

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