Question Details

(Solved by Expert Tutors) Write a complete program in a single class called StringDiff that does


Prompt the user to enter two strings:


Enter string one:


Enter string two:



Your program should assign each string to a

String

variable, say

inputStr1

and

inputStr2

. Note that the strings may have different lengths. Also note that the stringsmay have more than one word. The comparison stops when either one of the strings has no more characters.


It should then output a report the positions (index number) and character values where the two strings differ. It should also keep a count of the number of times there is a difference and report on that. For example, if the strings are "dealer" and "dollars", your code should report this:

1 e o2 a l4 e aNumber of differences: 3



This says that at string location 1 (the second position in the strings) the first string holds an 'e', the second an 'o'; at position 2 the strings hold an 'a' and an 'l'; and at position 3 the strings hold an 'e' and an 'a'.


Notice that "dealer" is shorter than "dollars"; your code should only report differences where both strings hold characters. Thus if the strings are "boy" and "bozo the clown" your code should only print

2 y zNumber of differences: 1



Remember that string positions are zero-based in Java. Therefore, we are considering the first position of a string to be zero. So, if the inputs were "yowser" and "nothing", the correct output would be:

0 y n2 w t3 s h4 e i5 r nNumber of differences: 5



One other consideration: the set of characters in a string includes punctuation and space characters as well as letters and numbers. Your code does not have to worry about what type of character it encounters. All your program needs to do is compare the two characters and report if they are different according to the project requirements described above.Your code must work with strings that contain more than one word.


For example:

"go umass" and "amherst!"

0 g a1 o m2   h3 u e4 m r5 a s6 s t7 s !Number of differences: 8



Note: we expect you to test your code by running it with the example given above!

Enter your code for the

StringDiff

class in the box below.


NOTE: Theimportstatement is already provided for your class. DO NOT submit code with animportstatement.

 


Solution details:

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Apr 19, 2020

EXPERT

Tutor

ANSWER RATING

YES, THIS IS LEGAL

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN A DEADLINE.

Order Now