Hashtable Counting Words

Jan 1, 2015

I was browsing around and I found a question asking to find how many times a word occurred in a sentence. I am using a hashtable, over kill yes but I need to use them more. However my counter is not working, not really sure why.You can see in the main method I have two repeating names but it returns 0.

package frequency;
import java.util.Hashtable;
public class CheckFrequency {
hashtable<String, Word> words = new Hashtable<String, Word>();

[code]....

View Replies


ADVERTISEMENT

Counting Words Contained In Address

Sep 19, 2014

I need to make this program work. It is supposed to count the words contained in the Gettysburg address. I went wrong somewhere but don't know where.

import java.util.Scanner;
public class gettysburgAddress {
public Static void main(String[] args) {
String URLString = "http://cs.armstrong.edu/liang/Lincoln.txt";

[Code] .....

View Replies View Related

Counting Number Of Words From User Input

Jan 2, 2015

I tried the following code, OK:

Java Code:

String temp = "hi this sf hello is new what is this";
String[] cmd = temp.split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

However, when i get the input from user , i didnt get the expected result:

Java Code:

System.out.println("Enter the input string to count the words: ");
String[] cmd = new Scanner(System.in).next().trim().split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

Now Result for above code:

Enter the string to count the words:

hi this is new

words are: 1

View Replies View Related

Program That Accept Words And Their Meanings Or Display List Of Words In Lexicographical Order

Apr 15, 2015

Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.

Use the JOptionPane class to enter the information.

Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:

- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.

For the output, the program should produce two scrollable lists:

- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.

So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.

WordMeaning Class:

public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;

[Code] .....

View Replies View Related

How To Traverse Through Hashtable

Mar 12, 2014

I was wondering how to traverse through a hashtable. I am stuck on how to implement an iterator for the values of some hashtable.

Java Code:

public Iterator<V> values() {
return new Iterator<V>(){
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;

[Code] ....

View Replies View Related

How To Get Method Of HashMap Or Hashtable

Jul 25, 2014

How get method of HashMap or Hashtable works internally in Java can any body let me know how does it work..

View Replies View Related

NullPointerException With Hashtable Object

Mar 1, 2014

I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,

Java Code:

public void siteGen(String user, String site)
throws ExcGenDatabad, ExcSiteNodomain, Exception {
System.out.println("calling siteGen, user: " + user + ", site: " + site);
String nginx_template;
String fpm_template;

[code]....

View Replies View Related

HashTable Insertion - Duplicate Records

Apr 20, 2015

I am having some difficulty adding a new item to the HashTable when a collision occurs. We can only use the basic utilities to code this, so we are coding a HashTable by hand. We have an array of length of 10, which each index holds or will hold a Node for a Linked List.

The code hashes fine, adds the item, but the problem exists when adding items that already been hashed. The project is much bigger, but this is the engine behind the rest, and I figured I would tackle this first.

The items we are adding are objects which are states containing different information, we hash based on the ASCII sum % tableSize.

Here is the code I am testing with to add items:

HashTable ht = new HashTable(10);
State az = new State("Arizona","AZ","W",2,"Y",2);
State fl = new State("Florida", "FL", "F", 2, "X", 2);
State hi = new State("Hawaii", "HI", "H", 3, "Z", 1);
State al = new State("Alabama", "AL", "A", 5, "W", 0);
ht.insert(hi);

[Code] ....

View Replies View Related

HashTable Remove Method Using Arrays

Nov 1, 2014

I'm writing the remove method, where you insert the key and it searches the key, if the key is found you remove the value inside the table and return that value, if they key is not found you return null. I did this method but is not returning anything in the main so I try to print inside an if to see if it was entering the condition and it appears to be looping, I'm using arrays because its an assignment

public V remove(K k) {
int key = funcionHash(k);
V key2 = (V) tabla[key].value;
int intento=1;
if(this.estatus[key]==1){
while(intento<this.tabla.length/2){
if(this.tabla[key].key.equals(k)){

[Code] ....

View Replies View Related

Double Hashing For Inserting Integer Into Hashtable?

Apr 29, 2014

I'm having a problem implementing double hashing when I insert a value into the table i get this for the output:

Insert []. Is there something I'm doing wrong? I'm not getting any errors

public static int size = 0;
public static ArrayList<Integer>[] a;
  public static void interactiveMode(Scanner input) {
int menuChoice = 0;
do {
System.out.println("
Interactive Mode:");

[code]....

View Replies View Related

Implement Separate-chaining Hashtable From Scratch?

Mar 19, 2014

I need to implement a separate-chaining hash table from scratch and I don't need to know the code or anything I would just like an explanation of how I would go about doing the algorithm for this perhaps pseudocode and then I can figure out the rest.

View Replies View Related

Double Hashing For Inserting Integer Into Hashtable

Apr 26, 2014

I'm having a problem with double hashing, its supposed to have the user insert an integer into the table and the integer is hashed into the table by the mod of the size of the table so say for instance table size 10 I insert 89 that inserts into 9 because 89%10=9 then i insert 18 that goes into 8 but then once i insert 69 its supposed to collide with index 9 and then uses 7-(69%7) for prime number double hashing...but it just goes into index 9 instead so in 9 it puts 89,69...there's no errors just the wrong output

System.out.print("Enter size of table: ");
int n = input.nextInt();
size=n;
a = new ArrayList[size];
for (int i = 0; i < size; i++) {
a[i] = new ArrayList<Integer>();

[code]....

View Replies View Related

Buffered Image - Color Palette Hashtable

Feb 12, 2014

How can I write a BufferredImage to an 8-bit .bmp using indexed colors stored in a <String,Color> Hashtable?

I've never used Hashtables before, and I didn't know color indexing existed until now, but I can do most other things in java fairly well.

I'm not looking for code, just the concept, as I really don't know how Hashtables work (although I could figure it out), and how color indexing does. I know how to write image files, just not indexed or with a specific number of bits. I am using Hashtables generated from GIMP.

EDIT: I mainly want to know how to save a BufferedImage as an indexed .bmp.

View Replies View Related

Accessing ArrayList Elements (Integer / String) And Put Them Into Hashtable

Mar 4, 2014

I have a data structure such as: ArrayList<ArrayList<Integer,String>

The data looks as [[1,2,3] [3,4] [99,98,40,32,45,65,1]]

I am trying to access each element and put them into a hashtable such as:

Hashtable<Integer,String>

With what I am doing below I am getting an out of bound error but can't see any other way of accessing the element

public static void hash(ArrayList<ArrayList<String>> list)
{
for(int i = 0; i < list.size(); i++)
{
int cnt = 0;
for(int y = 0; y < list.size(); y++)
{
if (! hashMap.containsValue(list.get(i).get(y)))
{
hashMap.put(cnt, list.get(i).get(y));
cnt++;
}
...

View Replies View Related

JSP :: Generate Hashtable And Display Its Key Value Pairs Back To Browser - How To Prevent Timeout

Jun 24, 2004

I have a jsp page that generate a hashtable and display its key-value pairs back to the browser. The problem is that it takes on an average about 15 minutes to build this hashtable, and as a result, I always get a timeout error. What can I do to avoid getting the timeout error without changing the server configuration for timeout

View Replies View Related

How To Add Counting Palindromes To Code

Apr 14, 2015

I have written a piece of code that takes a desired input file and calculates things such as words, characters, digits etc. I would like to make the program look better by counting palindromes.what I could add to my current code to count palindromes.My current code for counting other things that I would like to add plaindromes to.

// Loops through the file calculating the outcome.
while (input.hasNextLine()) {
lines++;
String line = input.nextLine();
chars += line.length();

[code]....

View Replies View Related

Counting Using Custom Scale

Aug 6, 2014

I'm having trouble creating a highly efficient algorithm for counting within a custom scale. This problem applies to futures trading, specifically treasuries contracts.

One specific treasury contract has 32 units before rolling over to the next whole number. So, the price scale looks something like this ...

1 0
1 1
1 2
...
1 29
1 30
1 31
2 0
2 1
...
2 30
2 31
3 0
...

If I pick a number (price) at random, let's say 1 28, and I want to add 8 units to that value, I should end up with 2 4. I can do this using brute force, calculating remainders, etc, etc....

View Replies View Related

Counting Duplicates In A Stack

Apr 11, 2014

Write a method compressDuplicates that accepts a stack of integers as a parameter and that replaces each sequence of duplicates with a pair of values: a count of the number of duplicates, followed by the actual duplicated number. For example, suppose a variable called s stores the following sequence of values:

bottom [2, 2, 2, 2, 2, -5, -5, 3, 3, 3, 3, 4, 4, 1, 0, 17, 17] top

If we make the call of compressDuplicates(s);, after the call s should store the following values:

bottom [5, 2, 2, -5, 4, 3, 2, 4, 1, 1, 1, 0, 2, 17] top

This new stack indicates that the original had 5 occurrences of 2 at the bottom of the stack followed by 2 occurrences of -5 followed by 4 occurrences of 3, and so on. This process works best when there are many duplicates in a row. For example, if the stack instead had stored:

bottom [10, 20, 10, 20, 20, 10] top

Then the resulting stack after the call ends up being longer than the original:

bottom [1, 10, 1, 20, 1, 10, 2, 20, 1, 10] top

If the stack is empty, your method should not change it. You may use one queue as auxiliary storage to solve this problem. You may not use any other auxiliary data structures to solve this problem, although you can have as many simple variables as you like. You may not use recursion to solve this problem. For full credit your code must run in O(n) time where n is the number of elements of the original stack.

I wrote a code but still having a problem with it , am I allowed to use 3 while loops ?

public void compressDuplicates(Stack<Integer> s ){
Stack<Integer> backup= new Stack<Integer>();
int count = 1;
while(!s.isEmpty()){
int temp = s.pop();

[Code] .....
 
// example 1

Expected output : bottom [5, 2, 2, -5, 4, 3, 2, 4, 1, 1, 1, 0, 2, 17] top

My output: //bottom [17, 2, 2, 2, 2, 2, -5, -5, 3, 3, 3, 3, 4, 4, 1, 0, 17, 17] top

View Replies View Related

Counting Duplicates In Array

Jan 23, 2013

It's supposed to count all of the duplicates in an array and print out how many occurrences of the value starting at whatever index, or if there are no duplicates state that. Basically:

No duplicates with value 1 beyond Index 0

There are 3 more occurrences of value 2 starting at index 1

There are 2 more occurrences of value 2 starting at index 2....

This is what I've got so far:

Java Code:

public static void main(String[] args) {
int[] arr = {1, 2, 2, 3, 4, 2, 4, 3, 0, 5, 3, 2};
for(int i = 0; i<arr.length; i++){
int count = 0;
for(int j = i+1; j<arr.length; j++){
if((arr[j] == arr[i]) && (i!=j)){
count++;
System.out.print("There are " + count + " more occurrences of ");
System.out.println(arr[i] + " starting at index " + i);
}
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Counting Cards GUI Interface

Dec 5, 2014

I curious for tips for moving forward within my current code for my counting cards GUI interface. I need two labels one for the card deck, and the other for the randomized card face. When the card face shows, in the count value text field the value of the card is added. For each card this is to happen through until the whole deck. There is also a card count text field to count how many cards have been dealt out. Now with that being said, I am being held back by getting the two labels to show in my GUI, the buttons show, but I need getting the cards and its value to show and initialize, with the card count in the card count text field.

import java.lang.Math;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CardsGui extends JFrame

[Code] ....

View Replies View Related

Queues - Reading And Counting

Jul 21, 2014

Here's what I'm trying to do:

Complete the body of the following method. Use a CharQueue to store the input line as it is being read. The parameter is an EasyReader from Appendix B of the text. Use the method in.charInput( ) to read and return the next character of the EasyReader, and use in.isEOLN( ) to determine whether the next input character is the end-of-line.

public static int counter(EasyReader in)
// Precondition: There is a line of input waiting to be read from in.
// Postcondition: A line of input has been read from in, up to but not
// including the newline character. The return value of the method
// is the number of times that the LAST character of the line appeared
// somewhere in this line.

[EXAMPLE Input: ABBXDXXZX - The value returned by counter would be 4 for this input since there are 4 X's in the input line.]

***When I look at this I understand that I'm being asked to finish the method, that I have 1 input, which is an "EasyReader" object called in and that I use a CharQueue object along with the method isEOLN( ) to grab characters from in while looking for an end of line and then sticking the values in the queue and then I can go through the queue and figure out the number of times that last character shows up in the queue. I just am at a loss on the "how".

View Replies View Related

Counting Mouse Button Clicks?

Jun 6, 2011

It complies an runs, but the textfield ends up being as big as the entire frame, and when I click the button, nothing happens.

import java.awt.event.*;
import java.applet.*;
import java.awt.*;

[Code].....

View Replies View Related

Method For Counting Vowels In A String

Nov 21, 2014

I have to take a user's input and count the number of vowels in a String. If I start with a lowercase vowel it gets counted, but if I start with an uppercase or different letter I get nothing. Either way, I can not get the counter to go higher than 1.

import java.util.Scanner;
public class countVowels
{
public static void main(String[] args)
{
Scanner kb=new Scanner(System.in);
System.out.println("Enter a sequence of letters:");
String letters=kb.next();

[code]...

View Replies View Related

Counting How Many Times A Value Appears In Array

Nov 23, 2014

I have this code but I can't seem to get it to work. It keeps saying that "count" cat be found and that it cannot return a value whose type is void.

Java Code: public class Cuantos {
static int getPosition(double listOfValues[], double targetValue ) {
int i,count,
position = -1;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue)

[code]....

View Replies View Related

Counting Number Of Paragraphs In A Text?

Apr 19, 2014

How do I count the number of paragraphs using a separate method?

import java.util.*;
import java.io.*;
public class WordStats1 {
public static void main(String[] args) {
try {
Scanner input = new Scanner(new FileReader("data.txt"));
PrintWriter output = new PrintWriter(new FileOutputStream(

[code].....

View Replies View Related

Creating A Loop For Counting Integers

Jul 16, 2014

working on assignment to count the total integers and have a seperate system.out if a non integer.

import java.util.Scanner;
public class CountInteger {
public static void main(String[] args) {
int correctCount = -1 ; // count number of integers
int data;
int sum = 0;

[code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved