Total members 11895 |It is currently Sun Dec 22, 2024 2:22 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Two words or phrases in English are anagrams if their letters, rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Some examples and non-examples:

* The eyes / they see (yes)
* moo / mo (no)
* Clint Eastwood / Old west Action! (yes)
* Dormitory / Dirty Room (yes)



Your job for this assignment: Write a two class application that reads in two words or phrases from the keyboard, and then judges if the two are anagrams.

(Note: this is a work-alone assignment. You may consult with others on design, etc., but you must submit your own work! Do not - repeat do not - submit the same solution as another student!).

The classes should be called: AnagramDriver, and Anagram

Some tips:

* use the String methods toLowerCase() and toCharArray(). The former takes all letters in a String and changes them to lower case; the latter converts a String into an array of characters.

* Very important: suppose you have two arrays of characters that are purported to be anagrams of each other. How do you tell? The single most important thing to do, before you write a single line of code, is to work out a paper and pencil algorithm that satisfactorily distinguishes between anagrams and non-anagrams.

* Your classes must be commented! In particular, each method must have a one line comment just below the header line, which tells what the method is supposed to do.

* Algorithm Idea #1: make a scoreboard for the letters a to z. Every time you encounter a letter in the first String, up its count by 1; Every time you encounter a letter in the second String, lower its count by 1. Accept if the scoreboard ends up as all 0s;

* Algorithm Idea #2: convert strings to arrays. March down first String. When you encounter a letter, look for it in the second String. If you find it, blank it out; if you don't find it - not anagrams. When you're all done, you've got anagrams if the second array contains no letters.




Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

Assignment ?? lol .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

java/anagram-in-java-t7720.html

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 3 posts ] 

  Related Posts  to : Java Anagram
 anagram in java     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 what is java     -  
 Java course     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 Java and SOAP     -  
 Steganography in java     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com