Writing a method to compute such an array from a string

Assignment Help JAVA Programming
Reference no: EM13865176

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.

Reference no: EM13865176

Questions Cloud

Should our evaluation of one lifetime of hard work : No security leaks had been found In accepting  Piraeus resignation President Obama praised Piraeus leadership during the Iraq and Afghanistan wars and said By any measure through his lifetime of service David Petra us has made our country safer and s..
Explain how to declare and manipulate data in arrays : Please respond to all of the following prompts: Explain how to declare and manipulate data in arrays. Explain the meaning of "array index out of bounds".
Speculators had better information about future exchange ra : If speculators had better information about future exchange rates, would their actions be more or less stabilizing than at present?
Do you think enlightened self-interest is a contradiction : Do you think enlightened self-interest is a contradiction in terms or is it a valid basis for all action? Evaluate whether our laissez-faire  free-market economic system does (or should) operate under this philosophy
Writing a method to compute such an array from a string : 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"
Write program that takes theelevator-nxtthrough calibration : Write the program that takes theElevator-NXTthrough a calibration and test sequence, as shown in thisvideo. Raise the car as far as it goes to the top (the top floor).
Irac method - grunden-martin vs fairmount : Solved the given cases using IRAC format- Case 1- Meran v. MacDonald, 2006 U.S. Dist. LEXIS 79069 (U.S. Dist. Ct. S.D. Cal.) and Case 2- Grunden-Martin v. Fairmount
Describes the challenges related to defining terrorism : Challenges related to defining terrorism
Explain the meaning of this phrase as you see it : Macintyre in his account of Aristotelian virtue, states that integrity is the one trait of character that encompasses all the others. How does integrity relate to as Macintyre said, the wholeness of a human life?David Starr Jordan (1851 1931) an edu..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Javascript validation - cgi program

CGI mailer script form-mail.pl to your server's cgi-bin directory, and change the permissions on the script to make it executable - BMIS 310

  Write a java application to ask number of assignments

Write a java application that accomplishes the following tasks with built in exception handling: ask the number of homework assignment students have submitted in a semester

  Write java program to print strings given at command line

Write a program Average.java which just prints strings that it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Digital image processing using java

Digital image processing using java ..create plugin using Jedit and run it in imageJ

  Numerical solution of a two-point boundary-value problem

How to combine both Secant and Runge-Kutta methods and make it to the two-point boundary-value - Numerical Solution of a Two-Point Boundary

  Write a recursive method called maxsum

write a recrusive method called maxSum that accepts a list of integers. L, and an integer limit n as parameters and use backtracking to find the maximum sum that can be generated by adding elements of L that do not exceed n.

  Build a simple text-based adventure game

Build a simple text-based adventure game. You can and probably should use our Missed Connections example as the foundation for your game.

  Implement a class person with two fields name and age

Implement a class Person with two fields name and age, and a class Car with three fields

  It should have an if statement

The following are hints given: It should have an if statement. This add method determines what number greater than or less than the other number, than it adds the positive or negative. I think this should be a private method.

  Write a program that establishes two savings accounts

Write a program that establishes two savings accounts with saver1 having account number 10002 with an initial balance of $2,000, and saver2 having account 10003 with an initial balance of $3,000

  Create both method contract and the method specification

Your demonstrations of how to create both method contract and the method specification for the GetCourseByCourseID() method of the CourseList class were very well received by your team members

  Write a restful web service demo example using spring mvc

Write a restful web service demo example using spring mvc

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd