Click here to Skip to main content
15,885,757 members
Home / Discussions / Java
   

Java

 
AnswerRe: Need peer-to-peer voice chat project Pin
Expert Coming14-Dec-08 12:29
Expert Coming14-Dec-08 12:29 
QuestionDevelopment IDE Pin
Muhammad Nauman Yousuf11-Dec-08 23:34
Muhammad Nauman Yousuf11-Dec-08 23:34 
AnswerRe: Development IDE Pin
Expert Coming14-Dec-08 12:27
Expert Coming14-Dec-08 12:27 
GeneralRe: Development IDE Pin
Muhammad Nauman Yousuf14-Dec-08 21:45
Muhammad Nauman Yousuf14-Dec-08 21:45 
GeneralRe: Development IDE Pin
Naruki23-Dec-08 17:36
Naruki23-Dec-08 17:36 
AnswerRe: Development IDE Pin
toxcct17-Dec-08 21:54
toxcct17-Dec-08 21:54 
QuestionNeed help with registry search and delete Pin
chooch048-Dec-08 1:45
chooch048-Dec-08 1:45 
QuestionImplementing a String collection class Pin
fazl3h6-Dec-08 8:04
fazl3h6-Dec-08 8:04 
need help in writng a class WordStore in order to compile WordTest1, WordTest2, WordTest3 and WordTest4. Need to create some sort of data structure to store words in WordStore. must have methods

public void add(String word)
Adds a String to the collection

public int count(String word)
Returns the number of times a String is in the collection

public void remove(String word)
Removes one occurrence of a String from the collection, or leaves the collection unchanged if the String does not occur in it.

code for WordTest1:

import java.util.Scanner;

class WordTest1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
WordGen.initialise(input);
System.out.print("Enter the number of words you wish to generate: ");
int n = input.nextInt();
WordStore words = new WordStore(n);
for(int i=0; i<n;> words.add(WordGen.make());
String line = input.nextLine();
System.out.println("Enter words to test, empty line to exit");
line = input.nextLine();
while(!line.equals(""))
{
String[] wordlist = line.split(" ");
for(int i=0; i<wordlist.length;> {
int count = words.count(wordlist[i]);
System.out.print("\""+wordlist[i]+"\" ");
if(count==0)
System.out.println("NOT generated");
else if(count==1)
System.out.println("generated once");
else
System.out.println("generated "+count+" times ");
}
line = input.nextLine();
}
}
}


code for WordTest2:
import java.util.*;

class WordTest2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
WordGen.initialise(input);
System.out.print("Enter the number of words you wish to generate initially: ");
int n = input.nextInt();
WordStore words = new WordStore(n);
for(int i=0; i<n;> words.add(WordGen.make());
System.out.print("Enter number of words you wish to test: ");
n = input.nextInt();
String[] testWords = new String[n];
for(int i=0; i<n;> testWords[i]=WordGen.make();
long time1,time2;
int count;
time1 = new Date().getTime();
for(int i=0; i<n;> count=words.count(testWords[i]);
time2 = new Date().getTime();
System.out.print("Time taken to test membership of "+n+" words ");
System.out.println("is "+(time2-time1)+"ms");
}
}

code for WordTest3:
import java.util.*;

class WordTest3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
WordGen.initialise(input);
System.out.print("Enter the number of words you wish to generate initially: ");
int n = input.nextInt();
WordStore words = new WordStore(n);
for(int i=0; i<n;> words.add(WordGen.make());
System.out.print("Enter number of words you wish to add: ");
n = input.nextInt();
String[] testWords = new String[n];
for(int i=0; i<n;> testWords[i]=WordGen.make();
long time1,time2;
int count;
time1 = new Date().getTime();
for(int i=0; i<n;> words.add(testWords[i]);
time2 = new Date().getTime();
System.out.print("Time taken to add "+n+" more words ");
System.out.println("is "+(time2-time1)+"ms");
}
}

code for WordTest4:
import java.util.*;

class WordTest3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
WordGen.initialise(input);
System.out.print("Enter the number of words you wish to generate initially: ");
int n = input.nextInt();
WordStore words = new WordStore(n);
for(int i=0; i<n;> words.add(WordGen.make());
System.out.print("Enter number of words you wish to add: ");
n = input.nextInt();
String[] testWords = new String[n];
for(int i=0; i<n;> testWords[i]=WordGen.make();
long time1,time2;
int count;
time1 = new Date().getTime();
for(int i=0; i<n;> words.add(testWords[i]);
time2 = new Date().getTime();
System.out.print("Time taken to add "+n+" more words ");
System.out.println("is "+(time2-time1)+"ms");
}
}
QuestionNeed Help Please Pin
AZBOY205-Dec-08 0:51
AZBOY205-Dec-08 0:51 
AnswerRe: Need Help Please Pin
Naruki8-Dec-08 19:55
Naruki8-Dec-08 19:55 
Questioncommunicating from one system to another using chat application Pin
ckanth3-Dec-08 19:36
ckanth3-Dec-08 19:36 
AnswerRe: communicating from one system to another using chat application Pin
Apurba Saha3-Dec-08 23:26
Apurba Saha3-Dec-08 23:26 
GeneralRe: communicating from one system to another using chat application Pin
ckanth4-Dec-08 22:53
ckanth4-Dec-08 22:53 
QuestionHow to create an exe file? Pin
Cheyahere3-Dec-08 3:20
Cheyahere3-Dec-08 3:20 
AnswerRe: How to create an exe file? Pin
Expert Coming14-Dec-08 12:31
Expert Coming14-Dec-08 12:31 
QuestionDifference between JPA and Hibernate Pin
sunil_jvfrm3-Dec-08 3:17
sunil_jvfrm3-Dec-08 3:17 
QuestionChanging locale for updates! Pin
Naruki2-Dec-08 13:24
Naruki2-Dec-08 13:24 
QuestionJava UTF8 applet Pin
Allan Larson26-Nov-08 15:12
Allan Larson26-Nov-08 15:12 
AnswerRe: Java UTF8 applet Pin
Naruki23-Dec-08 17:38
Naruki23-Dec-08 17:38 
GeneralRe: Java UTF8 applet Pin
Allan Larson24-Dec-08 6:11
Allan Larson24-Dec-08 6:11 
QuestionGraph layout Pin
ventomito26-Nov-08 8:06
ventomito26-Nov-08 8:06 
QuestionHelp mee,,,,, I'm confused,,,, Pin
VANDAWAA25-Nov-08 15:09
VANDAWAA25-Nov-08 15:09 
QuestionJavascript - href - servlet - java Pin
asifhirani78625-Nov-08 14:51
asifhirani78625-Nov-08 14:51 
Questionjava code for creating a unstructered p2p n/w Pin
venkatesh1111121-Nov-08 22:35
venkatesh1111121-Nov-08 22:35 
QuestionJava to COM Bridge Pin
railay2919-Nov-08 4:58
railay2919-Nov-08 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.