Write a java program in one file to determine if a string


Write a program called Assg3.java to solve the following problem.

Write a java program in one file to determine if a string is an anagram of another string where a typical run of your program is to be as follows.

% java Assg3 restful fluster
"restful" is an anagram of "fluster"

The two items provided on the command line may include spaces and punctuation marks. All non-letters are to be ignored as if they were absent. Convert text to lower case (use a method in the String class) before attempting to determine whether one argument is an anagram of the other. To ensure that the spaces are preserved in these two command-line arguments, use double quotation marks as follows, when running your program.

% java Assg3 "Forty five" "Over Fifty"
"Forty five" is an anagram of "Over Fifty"

If the first argument is not an anagram of the second, say 'is not' instead of 'is' in the output text, but otherwise leave it in the same form.

If you need a hint or help in inventing how this program should be organized, speak with the instructor or with a T.A. and we'll gladly suggest how you can proceed to solve this problem. Read the hint below first.

Hint: Two items are anagrams (of each other) when they contain the same number of 'a's and the same number of 'b's, etcetera, and the same number of 'z's. So a table indicating how many of each letter is in an item could be computed from that item, as follows.

 

"Forty five"

 

a

0

 

b

0

 

c

0

 

d

0

 

e

1

 

f

2

 

g

0

 

h

0

 

i

1

 

j

0

 

k

0

 

l

0

 

m

0

 

n

0

 

o

1

 

p

0

 

q

0

 

r

1

 

s

0

 

t

1

 

u

0

 

v

1

 

w

0

 

x

0

 

y

1

 

z

0

Now two items are anagrams exactly when their respective tables are equal. A simple way to represent such a table is as an array A of 26 integers. Then A[0] is the number of 'a's, A[1] is the number of 'b's and so forth. Given a variable ch of type char, A[ch-'a'] is A[0] if the value of ch is 'a', or is A[1] if the value of ch is 'b', and so forth. And the condition 'a'<=ch && ch<='z' is true exactly when the value of ch is a lower case letter, as indicated in class.

Writing a method to compute such an array from a String and return it, and a second method to take two such arrays and return a boolean indicating whether they are equal is sufficient to write a simple solution the remainder of which is the main method.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a java program in one file to determine if a string
Reference No:- TGS01150097

Expected delivery within 24 Hours