ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 36 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 29 Apr 2017 My Price 11.00

Write a complete program in a single class called StringDiff

Write a complete program in a single class called

StringDiff

that does following:

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 o
2 a l
4 e a
Number 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 z
Number 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 n
2 w t
3 s h
4 e i
5 r n
Number 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 a
1 o m
2   h
3 u e
4 m r
5 a s
6 s t
7 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.

Answers

(11)
Status NEW Posted 29 Apr 2017 05:04 AM My Price 11.00

-----------

Not Rated(0)