4 Replies - 2134 Views - Last Post: 01 December 2009 - 10:07 PM Rate Topic: -----

#1 abpunisher901  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-May 09

word list and words..

Posted 01 December 2009 - 09:30 PM

i need entire help to write this program.. correctly my teacher said im doing it wrong.. i show outline she wrote to me


Program: WordList (using arrays)

You may NOT use any of the specialized methods from the Array class. For this program I want you to write your own search, sort, and other methods using what we have learned about arrays so far.

You may use the toCharArray method from the String class we discussed in the lecture.

program that allows a user to enter up to 100 words and stores the words the user entered in a list. This means the user can enter less than 100 words if they would like to. The words should be stored in an array. The program will allow the user to manipulate the word list in various ways.

The program should begin by displaying the following menu:

WORD LIST MENU
--------------
1) Add Word
2) Remove Word
3) List Palindromes
4) Resort List Based on Number of Letters
5) Resort List Alphabetical
6) Print the list
7) Quit
Please make a selection:

-If the user selects 1 to add a word to the list: The program should prompt the user to enter a word they would like to add to the list. Assume the user only enters one word. The program should then call a method named addWordAlpha that adds the word the user entered to the word list in alphabetical order. So if the word being added was “adam” and the word currently in the list was “bricks”, “adam” should be added before “bricks” in the array. So the addWordAlpha method is sorting the word list alphabetically as words are added to it. Do not allow the user to add a word to the list if the array is full (it already contains 100 words).

-If the user selects 2 to remove a word from the list: The program should prompt the user to enter a word they would like to be removed from the list. Assume the user only enters one word. The program should then call a method named removeWord that removes the word the user entered from the list. This method should return true if the word was successfully removed from the list and false if the word was not found in the list and therefore couldn’t be removed. Make sure not to leave any elements in your array that don’t contain any data after removing the word from the list.

-If the user selects 3 to list palindromes: The program should call a method named listPalindromes that inspects every word in the word list array to see if it is a palindrome. The listPalindromes method should print all words that are palindromes to the screen. (See below for the definition of a palindrome)

-If the user selects 4 to resort the list based on the number of letters: The program should call a method named sortNumLetter that sorts the list based on the number of letters in each word. So if before this method was executed, the order of the list was: apple, fish, zoo; then after this method is executed the list should be: zoo, fish, apple.

-If the user selects 5 to resort the list alphabetically: The program should call a method named sortAlpha that sorts the list in alphabetical order. So if before this method was executed, the order of the list was: zoo, fish, apple; then after this method is executed the list should be: apply, fish, zoo. Note that if the sortNumLetter method wasn’t called this method will not change the list.

-If the user selects 6 to print the list: The program should call a method named printList that prints out all of the elements in the word list array to the screen.

-If the user selects 7: End the program

-If the user makes a numerical choice other than 1-7: Print an error message to the screen

You are required to create the following algorithms for your program. Implement these algorithms as methods either in your procedural program or your object oriented program.
• addWordAlpha – This method should accept as an argument a name to be added to the array. The name should be added to the array in alphabetical order by first name. In other words once the user is finished entering names in the array, they should be already sorted by first name in alphabetical order.
• removeWord – This method should accept as an argument a name to be removed from the array. Once the item to be removed is found, the method should remove the item and rearrange the rest of the elements in the array accordingly.
• isPalindrome – This method should accept one string as an argument and return true if it is a palindrome and false if it is not
• listPalindromes – This method should inspect every element in the list and print each one that is a palindrome (notice, this method will need to call the isPalindrome method).
• sortNumLetter – This method should resort the list based on the number of letters in each word. The strings should be sorted starting with the ones with the smallest number of letters and ending with the ones with the largest number of letters.
• sortAlpha - This method should resort the words in the list in alphabetical order
• printList – This method should print the list of names as they are currently stored in the array.

You may create as many additional methods as you would like to make your program more efficient and readable.

What is a palindrome? A palindrome is a series of letters that spell the same word or phrase both backwards and forwards. In this program you are only testing single words. So “bob” and “anne” are examples of palindromes. “Cat”, “dog”, and “grapes” are examples of words that are not palindromes. See next page for a list of palindromes to test with.

SOME HINTS:
1. Don’t forget the various String class methods you have learned such as charAt() and compareToIgnoreCase()
2. You will need to account for the special case when the user is trying to add a word to the beginning of the list.
3. You may need to account for the special case when the word the user is trying to add is alphabetically the last word in the list.
4. Make sure to adjust the list size when you are adding and removing words
5. Make sure not to let the user add a word if the list is already full.
Some Examples of Palindromes to Test your program with
• Aibohphobia
• Alula
• Cammac
• Civic
• Deified
• Deleveled
• Detartrated
• Devoved
• Dewed
• Evitative
• Hannah
• Kayak
• Kinnikinnik
• Lemel
• Level
• Madam
• Malayalam
[/code][code]
•	Minim 
•	Murdrum 
•	Peeweep 
•	Racecar 
•	Radar 
•	Redder 
•	Refer 
•	Reifier 
•	Repaper 
•	Reviver 
•	Rotator 
•	Rotavator 
•	Rotor 
•	Sagas 
•	Solos 
•	Sexes 
•	Stats 
•	Tenet 
•	Terret 
•	Testset 
[code]public class WordList
{
 public static void main(String[]args)
 {
   //these are your main variables
   int wordArr = new int[200];
   int currSize = 0;  //number of words in the list


   //print your menu - get user choice


   if (choice == 1)
   {
	 //ask user what word they would like to add save in variable
	 //I'll call the variable wordToAdd...this variable and the array MUST
	 //be passed  into your method - see below
	//also you need to pass the currSize of the list into the method

	//Before you call the method remember to ask the user what string to
//add and save in variable wordToAdd - remember the method returns
true or //false
	 if(addWord(wordArr, wordToAdd, currSize) == true)
	  {
		 //if word add is successful and returns true increase currSize
		 currSize++;
	  }

	  else
	  {
		 //print message saying list is full and can't add word
	  }


	}  //end first if

	//add other else ifs here

  }

  //close main

  //addWord method  -- method should return true if word is successfully
  //added and false if not
  public static boolean addWord(String [] arr, String w, int numItems)
  {
   //right here I would call a method to sort the list
   //for now let's just add it in any order

   //the key is if the list is not full add the word to the end
   //and return true, else don't add word and return false
   if(numItems == 200)  //array is full return false
   {
	 return false;
   }
   else
   {
	  //word to the end...the end is at position numItems since
	  //array index numbering starts at zero
	  arr[numItems] = w;
	  return true;


Is This A Good Question/Topic? 0
  • +

Replies To: word list and words..

#2 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • Posts: 378
  • Joined: 28-November 09

Re: word list and words..

Posted 01 December 2009 - 09:43 PM

this website has a good faith policiy where you must show effort before you get code help so I will give you some pointers.
1.add a word- simple they hit one you get their next input and add it to the list
2.remove a word-get the word the user wants to remove, and use a for loop to check your current list, and when you find the word remove it
3.palendroms- you can make a for loop that turns each word around and call a recursion method to check if it is a palendrom if it is add it to a seperate array.
4. use length() to go through the array grabbing one entry at a time then comparing it to the rest of the array( you can use a nested for loop to do this)
5.use compareTo() http://java.sun.com/...va.lang.Object)
6.print - easy
7.quit - System.exit(0)

This post has been edited by ianian112: 01 December 2009 - 09:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 TriggaMike  Icon User is offline

  • Using up all your 1's and 0's
  • member icon

Reputation: 85
  • View blog
  • Posts: 1,103
  • Joined: 26-September 08

Re: word list and words..

Posted 01 December 2009 - 09:45 PM

I'm a little confused by the code you posted, is that your code that the teacher said was all wrong, or is that code your teacher provided?

This post has been edited by TriggaMike: 01 December 2009 - 10:02 PM

Was This Post Helpful? 0
  • +
  • -

#4 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • Posts: 378
  • Joined: 28-November 09

Re: word list and words..

Posted 01 December 2009 - 09:50 PM

The code he posted might be by him but I dont think so. There is so many comments it looks more like a teacher's explaining what to do. But you never know!He just posted the dice program >.>

This post has been edited by ianian112: 01 December 2009 - 09:51 PM

Was This Post Helpful? 0
  • +
  • -

#5 abpunisher901  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-May 09

Re: word list and words..

Posted 01 December 2009 - 10:07 PM

yes it was posted by my teacher and this is wat she wrote to me srry bout that


 public class WordList
{
 public static void main(String[]args)
 {
   //these are your main variables
   int wordArr = new int[200];
   int currSize = 0;  //number of words in the list


   //print your menu - get user choice


   if (choice == 1)
   {
	 //ask user what word they would like to add save in variable
	 //I'll call the variable wordToAdd...this variable and the array MUST
	 //be passed  into your method - see below
	//also you need to pass the currSize of the list into the method

	//Before you call the method remember to ask the user what string to
//add and save in variable wordToAdd - remember the method returns
true or //false
	 if(addWord(wordArr, wordToAdd, currSize) == true)
	  {
		 //if word add is successful and returns true increase currSize
		 currSize++;
	  }

	  else
	  {
		 //print message saying list is full and can't add word
	  }


	}  //end first if

	//add other else ifs here

  }

  //close main

  //addWord method  -- method should return true if word is successfully
  //added and false if not
  public static boolean addWord(String [] arr, String w, int numItems)
  {
   //right here I would call a method to sort the list
   //for now let's just add it in any order

   //the key is if the list is not full add the word to the end
   //and return true, else don't add word and return false
   if(numItems == 200)  //array is full return false
   {
	 return false;
   }
   else
   {
	  //word to the end...the end is at position numItems since
	  //array index numbering starts at zero
	  arr[numItems] = w;
	  return true;

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1