Total members 10261 | Gratitudes |It is currently Wed May 23, 2012 8:50 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 3 posts ] 
Author Question
 Question subject: Java Anagram
PostPosted: Mon Jul 20, 2009 3:06 am 
Offline
Newbie
User avatar

Joined: Mon Jul 20, 2009 2:58 am
Posts: 2
Has thanked: 0 time
Have thanks: 0 time

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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Java Anagram
PostPosted: Tue Jul 21, 2009 11:42 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
Assignment ?? lol .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Java Anagram
PostPosted: Mon Sep 26, 2011 5:05 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
java/anagram-in-java-t7720.html

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 3 posts ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder
 java

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Yahoo [Bot] and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team