enter the word:A try #0 word=A, randomWord=0, score =14 try #1 word=A, randomword=T, score =19 try #2 word=A, randomword=G, score =6 try #3 word=A, randomword=V, score =21 try #4 word=A, randomword=K, score =10 try #5 word=A, randomword=C, score =2 try #6 word=A, randomword=L, score =11 try #7 word=A, randomword=R, score =17 try #8 word=A, randomword3DV, score =21 try #9 word=A, randomword=D0, score =14 try #10 word=DA, randomword=L, score =11 try #11 word=A, randomword=X, score =23 try #12 word=A, randomword=I, score =8 try #13 word=A, randomword=B, score =1 try #14 word=A, randomword=X, score =23 try #15 word=A, randomword=A, score =0

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How to write a program in java that ask the user for an input word(use the String method toUpperCase to convert the word to all upper-case characters), then have the program keep looping, generating random strings until the random string matches the user word and keep track of how many loops were required to match. Each time through the loop, your program should output the user’s word, the random string, and the difference score. The difference score is the sum of the absolute value of the difference between each character in the random string and the user’s input string. For example, if the random string was “ABC” and the target string was “AAA”, then the difference score is 3 (abs(A-A) + abs(A-B) + abs(A-C) = 0 + 1 + 2 = 3). You can get at the characters of a string, using the String charAt and absolute value is the abs method of the java.lang.Math class. To generate random strings, in a loop, generate random characters to build up a random string the same length as the user word. To generate a random character make a string of the alphabet String alpha = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; then generate a random index into that string (use util.Random.nextInt method limited to generating values between 0 and 25 and use the concatenation operator (+) to add the random character to the random string you are building).

output should look simiar to screenshot

enter the word:A
try #0 word=A, randomWord=0, score =14
try #1 word=A, randomword=T, score =19
try #2 word=A, randomword=G, score =6
try #3 word=A, randomword=V, score =21
try #4 word=A, randomword=K, score =10
try #5 word=A, randomword=C, score =2
try #6 word=A, randomword=L, score =11
try #7 word=A, randomword=R, score =17
try #8 word=A, randomword3DV, score =21
try #9 word=A, randomword=D0, score =14
try #10 word=DA, randomword=L, score =11
try #11 word=A, randomword=X, score =23
try #12 word=A, randomword=I, score =8
try #13 word=A, randomword=B, score =1
try #14 word=A, randomword=X, score =23
try #15 word=A, randomword=A, score =0
Transcribed Image Text:enter the word:A try #0 word=A, randomWord=0, score =14 try #1 word=A, randomword=T, score =19 try #2 word=A, randomword=G, score =6 try #3 word=A, randomword=V, score =21 try #4 word=A, randomword=K, score =10 try #5 word=A, randomword=C, score =2 try #6 word=A, randomword=L, score =11 try #7 word=A, randomword=R, score =17 try #8 word=A, randomword3DV, score =21 try #9 word=A, randomword=D0, score =14 try #10 word=DA, randomword=L, score =11 try #11 word=A, randomword=X, score =23 try #12 word=A, randomword=I, score =8 try #13 word=A, randomword=B, score =1 try #14 word=A, randomword=X, score =23 try #15 word=A, randomword=A, score =0
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education