GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Apr-2008, 20:14
sneakerhead724 sneakerhead724 is offline
New Member
 
Join Date: Mar 2008
Posts: 17
sneakerhead724 is an unknown quantity at this point

Coding Help


Hey Guys I need some help in completing this code. Its for a final prject in my class. Its worth alot of my grade PLEASE AND THANK YOU!!!

JAVA Code:
/**
*	An array implementation of a list of Words. The array is dynamic, able to grow if needed
*	when an element is added to the list.
*
*	method to complete: buildList()
*
*	methods to be written also
*		add
*		contains
*		numCharacters
*		wordsWithSubstr
*		wordsWithLength
*		findLongestWord
*		longestWords
*		wordsBetween
*		
*/

import java.io.*;
import java.util.*;

public class WordList {

	// instance variables
	private String [ ] list;
	private int count;
	
	/**
	*	Constructs an empty list with the specified initial capacity
	*
	*	@param int capacity - the initial capacity of the list
	*/
	public WordList(int capacity) {
	
		list = new String[capacity];
		count = 0;
	}
	
	/**
	*	prompts user for filename, opens the specified file, and builds the list of Words
	*	from the file.
	*
	*	TO BE COMPLETED
	*/
	public void buildList() throws IOException{
	
		// build an object for keyboard input
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
		
		// prompt for file name
		System.out.println();
		System.out.print("Enter the name of the file to open: ");
		String filename = keyboard.readLine();
		
		// build an object for file input
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(new File(filename)));
		} catch (FileNotFoundException e) {	// check for valid filename
			System.out.println("File not found.");
			System.exit(-1);				// exit if invalid filename
		}
		
		// read the file
		String line; 
		while ((line = file.readLine()) != null) {
		
			StringTokenizer stk = new StringTokenizer(line, " .,:;?!");
			while(stk.hasMoreTokens()) {
			
				String word = stk.nextToken();
				
				//*************************************************
				// ADD CODE TO COMPLETE METHOD AFTER THIS BLOCK
				//    a) convert word to all lower case characters
				//    b) only add to the list if the word is not already in the list
				//    c)  only add to the list if the word length > 3
				//**************************************************
				
				
				
			}
		}
	}

	
	





//******************************************************************
//
//				The following methods are complete
//
//******************************************************************


	/**
	*	Displays all of the elements of the list to the monitor
	*/
	public String toString() {
		
		String str = "";
	
		for(int i = 0; i < count; i++) {
		
			str += list[i] + "\n";
		}
		
		return str;
	}
	
	/**
	*	Returns the number of elements in this list. 
	*
	*	@return int - the number of elements in this list. 
	*/
	public int size() {
	
		return count;
	}
	
	/**
	*	Tests if this list has no elements. 
	*
	*	@return boolean - true if this list has no elements; false otherwise. 
	*/
	public boolean isEmpty() {
	
		return count == 0;
	}
	
	/**
	*	Returns the current number of slots available in this list. 
	*
	*	@return int - the current number of slots available in this list. 
	*/
	public int capacity() {
	
		return list.length;
	}
	
	/**
	*	Tests if this list has has room for no more elements. 
	*
	*	@return boolean - true if this list has no available slots; false otherwise. 
	*/	
	public boolean isFull() {
	
		return count == capacity();
	}
	
	/**
	*	Increases the capacity of this WordList instance, if  necessary, to ensure  
	*	that it can hold at least the double the current capacity of the list  
	* 
	*/
	private void resize() {
	
		String [] temp = new String [capacity() * 2 + 1];
		
		for (int i = 0; i < size(); i++) {
		
			temp[i] = list[i];
		}
		
		list = temp;	
	}
}

method to complete:
• buildList(): this method already grabs each individual word from the file. This method will add each word after it converts it to its lower case form, and if the word is not already in the list, and has a length greater than three characters.

methods to be written by student
• add(String wd): appends valid words to the list, updates the list count, and resizes the list if necessary
• contains(String other): returns the position index if other is in the list, -1 otherwise
• numCharacters(): returns the sum total of all characters of all the words in the list
• wordsWithSubstr(String substr): returns a new WordList with every word in the list that contains the substr. For example, if substr is “mom”, and the word moment is in the list, then moment will be added to a new WordList as well as any other word that contains “mom”, whether “mom” is the first three characters, the last three characters, or three adjacent characters somewhere in the word. Then this new WordList is returned. Hint: you will probably want to use the indexOf() method of the String class in writing this method.
• wordsWithLength(int value): returns a new WordList with every word in the list that has the length (or number of characters) of value
• wordBefore(String word1) returns a new WordList with every word in the list, that comes before word1 alphabetically. word1 will not necessarily be in the list.

For the following WordList list: {cat, ant, dog, ape, bear, monkey, rat}

The statement WordList newList = list.wordBefore(“anvil”); will return:
{ant }

The statement WordList newList = list.wordBefore(“dog”); will return:
{cat, ant, ape, bear}

The statement WordList newList = list.wordBefore(“ant”); will return:
{ } // an empty list


• findLongestWord(): returns the length of the longest word in the list: If relativity is the longest word this method returns 10, not relativity
• longestWords(): returns a new WordList with every word in the list that has the same length (or number of characters) of the longest word in the list. Hint: You should use the methods findLongestWord() and wordsWithLength(int value) to solve this problem.





I finished most of it. =/
Last edited by LuciWiz : 08-Apr-2008 at 02:53. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 08-Apr-2008, 18:06
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road

Re: Coding Help


What is the problem You have?
  #3  
Old 08-Apr-2008, 18:09
sneakerhead724 sneakerhead724 is offline
New Member
 
Join Date: Mar 2008
Posts: 17
sneakerhead724 is an unknown quantity at this point

Re: Coding Help


Just need help finishing the rest of the code following the requirements =/ please
  #4  
Old 08-Apr-2008, 18:31
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road

Re: Coding Help


Quote:
//*************************************************
// ADD CODE TO COMPLETE METHOD AFTER THIS BLOCK
// a) convert word to all lower case characters
// b) only add to the list if the word is not already in the list
// c) only add to the list if the word length > 3
//**************************************************

Hi

This is simple example that you asked part of your posts. I thing you can catch the solution from this code

JAVA Code:
public class gidhelp {

	
	public static void main(String[] args) {
	String asdfg="WELLCOME";
	// you may add or read any string
	System.out.println(asdfg+ "  Converted to lower case   "+asdfg.toLowerCase());
	// this will converts the all the string to lower case
	
			if (asdfg.length()>3) {
					System.out.print(asdfg+ "   Length is greater than 3 that is   "+asdfg.length());
			}
			// this block going to checks the length of the String bigger than 3  
	}

}

Inside the if block you can check the existance of the word on your lists using loop.

I hope it may helpfull to you
best wishes to your project and course will be success.
  #5  
Old 09-Apr-2008, 07:20
sneakerhead724 sneakerhead724 is offline
New Member
 
Join Date: Mar 2008
Posts: 17
sneakerhead724 is an unknown quantity at this point

Re: Coding Help


ok i Understand it but to implement im going to need the add method which is one of the methods i also have to provide code for. Its due tonight by midnite HELP !! =/
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run exe file in C++ coding sitha C++ Forum 4 01-Mar-2007 23:19
coding wont read the file shatred C++ Forum 3 02-Dec-2006 21:02
Coding Contest #1 davis Miscellaneous Programming Forum 0 12-Jun-2006 08:29
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 20:48
C Coding Style dsmith Miscellaneous Programming Forum 10 24-Feb-2004 06:23

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:34.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.