Word Counter Program With A Constructor

Mar 4, 2014

Create a WordCounter class with a constructor that takes a file name as a parameter. The class should have two fields: one for the file name and one for a HashMap to store word count information. The constructor should call a private method, countWords, that reads in the file and counts the word frequencies. The class should contain a get method for each field, as well as a print method that prints out the map in the following format:word:frequency. When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)You should include the sample text file on Blackboard

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class WordCounter

[Code] .....

View Replies


ADVERTISEMENT

Word Counter - Show Number In Square Box

Jan 3, 2015

My code compiles and runs just fine, i'd just like to get creating a small square box that shows number of words used next to the "word count = ". i'd wanto to press the count words button to count and show the number in the square box. here is my code.

import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class wordCount extends JFrame implements ActionListener

[Code] .....

View Replies View Related

Creating Number To Word Program?

Apr 1, 2015

I was given the assignment of creating a number to word program for my first college java programming homework.

Here is what I have created so far :

import java.util.*;
public class PrintNumberInWord { // saved as "PrintNumberInWord.java"
public static void main(String[] args) {
int number = 5;
Scanner sc = new Scanner (System.in); {
System.out.println ("Enter a number");
System.out.println(" ");
if (number == 1) {

[Code] .....

The first lines were made for us so we could follow a guideline, however, no matter what I type the command prompt displays 5 to me, I know thats because 5 is defined in the beginning but backspacing 5 causes the program not to work at all, how can I get this program to work properly?

View Replies View Related

Program To Count Character Word And Line From A File?

Dec 27, 2014

public static void main(String[] args) throws FileNotFoundException, IOException{
// TODO code application logic here
FileReader fr = new FileReader("gautam.txt");
BufferedReader br = new BufferedReader(fr);
  int line = 0;
int word = 0;
int character = 0;
String s;
while((s=br.readLine())!=null)

[code]...

how to count the character from file

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?

/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses.
*/

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
  Scanner kb = new Scanner(System.in);
  String guess;

[Code] ....

View Replies View Related

Java Program For Counting Specific Character In Word

Jun 27, 2014

I am trying to make a java program which should count the occurrences of a specific character in a string. I have 1 error - "cannot find method charAt(int)". Here is what I have.

import java.util.Scanner;
public class ch4q5 {
public static void main(String[] args) {
String input ;
String t ;
int c = 0;

[Code] ....

View Replies View Related

Write A Program To Reverse Each Word In Line (sentence)

Jul 3, 2014

Write a program to reverse each word in line(sentence)?

View Replies View Related

Program That Memorizes Elements Formed By A Word And A Number

May 24, 2014

i'm trying to do a program that memorizes the elements formed by a word and a number. For example, if I write ABB 3, AB 2, ABB -2, ABC 5, ZZ 2 the program will write:

ABB 1 (the result of abb (3-2))
ABC 5
AB 2
ZZ 2

Also, should write:

2 AB ZZ
5 ABC
1 ABB

I've tried to do it with a TreeMap but i don't know how it works.

View Replies View Related

Multi-word Hangman Game - Spaces Not Displayed When Program Run

Apr 9, 2015

I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.

It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.

I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
Scanner kb = new Scanner(System.in);
String guess;
String guesses = "";
int wrongGuess = 8;

[Code] ....

View Replies View Related

Java Program To Translate English Into Pirate - Word Pair Class

Apr 5, 2015

I am making a java program that translates English into Pirate. I need working with the Word Pair class. I'm not sure what needs to be passed to the default constructor. And how to do the method that will take the words and pair them. here is my code and the dictionary file

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner; 
public class PirateTranslator {
public static void main(String[] args)
 
[Code] .....

View Replies View Related

Binary Tree - Storing Each Word As String And Int Frequency For Each Time Word Occurs

Apr 27, 2015

I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.

As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?

public void findUnique() {
System.out.println("There are " + findUniqueWords(root, 0) + " unique words.");
}
private int findUniqueWords(Node subTree, int uniqueCount) {
// Base Case: At the end of the branch
if(subTree == null){
return uniqueCount;

[Code] ....

View Replies View Related

AutoCorrect / Replace A Word That Is Similar To A Word In File Text

Mar 13, 2015

The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",

Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?

import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class WahidMuhammadA3Q2{
String fileName = "AutoCorrectMe.txt";
public static void main (String [] args){

[Code] ....

View Replies View Related

I/O / Streams :: How To Use Java To Generate Word Document From A Word Template

Aug 19, 2014

I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.

I found this example: [URL] which is similar except it uses xml template instead of word template, how to make it work to change the template from xml to word (docx) template?

View Replies View Related

Comparing Typed Word To The Set Word In Object

Jul 1, 2014

Here's My Code.

package bin;
import java.util.Scanner;
public class AppletMain{
public static void main(String[] args){
Scanner oneinput = new Scanner(System.in);
String one;

[Code] ....

I am trying to get it to compare the word I type in to the set word in the object 'secretword'. I have tried everything from equal to == to compareTo, I even created a two hundred line program to do this SIMPLE problem.

View Replies View Related

Word Game (how To Check That Word Is In Dictionary)

Apr 21, 2014

import java.io.*;
import java.util.Random;
import java.util.Scanner; 
public class WordGame
{
public static void main(String[] args) throws IOException
{
final int RANDOM_LETTERS_COUNT = 10;
final int TRIALS = 10;
int score = 0;

[Code] ....

View Replies View Related

Implementing A FPS Counter

Jan 17, 2014

Ok, so I'm making a game with a space ship that flies around the universe and discovering new planets. It works fine so far, but I'm looking to make it perform better and be better compatible with lesser-processors.So, I'm trying to put in an FPS counter and an entirely new game loop so that my game can decide for me what FPS I should use.

I have two classes. Heres the big, main one: [Java] package cyentw.game.src; import java.awt.Color; import java.awt.Font; impor - Pastebin.com *I want to change the loop and put an FPS counter in around line 456, you can scroll past the rest if you'd like*And heres the init frame one, in case you'd like to see it for some reason.

Java Code:

package cyentw.game.src;
import javax.swing.JFrame;
public class Start extends JFrame{
public static JFrame frame;
public static int WIDTH = 500;
public static int HEIGHT = 500;
public Start() {

[code]....

how to make my game loop as quickly (or a bit slower) as it can, and my FPS is static.

View Replies View Related

Second Counter To Minutes

Apr 7, 2014

I have a timer where it counts down from 300 to 0 then does something. But I want the display for the clock to show the time in minutes. I tried:

double showTimeLeft = timeLeft / 60;
o.setDisplay(String.format("%.2f", showTimeLeft) + " Minutes");

But Every so many seconds it skips like:

Time = 3.38
Time = 3.37
Time = 3.35
Time = 3.34

It skipped 3.56

How to do this right?

View Replies View Related

Increment Counter By Recursion

Mar 22, 2015

I have a question related to the code below, that I do not understand. The aim is to count all files and subdirectories in an ArrayList full of files and subdirectories. So I have to count every file and every subdirectory.

The code concerning counting files is clear to me - every time d is of the type file I have to increment n by one. However I thought that I have to do the same thing in case d is a directory, so I would have written the same code for directories.

So what does "n += ((Directory) d).countAllFiles();" mean? In my understanding the method countAllFiles() is applied again on the object Directory ( as Directory is the class that contains this method), but how is n incremented by this? I thought n should be incremented by one as we did with files.

public int countAllFiles() {
int n = 0;
for(SystemFile d : content) {
if(d instanceof File) {
n++;

[Code] ....

View Replies View Related

Confirm Dialog And Counter

Mar 29, 2014

This is the code I have written so far. This program calculates tax from multiple tax payers.

import javax.swing.JOptionPane;
public class CalcutateTax
{
public static void main (String [] args)

[code]....

The problem is I cant think how to ask the use if he wants to calculate tax due for another taxpayer. If the user says yes, keep calculating, otherwise exit from the program. And how do I keep count of how many people got their tax calculated? Say for example,

JOptionPane.showMessageDialog (null, " We calculated tax for " + xnumber + " number of people.");

This is the question asked on my assignment ask the user if he wants to calculate the tax due for another taxpayer if so, do it again.At the end of the main method, output a message in a dialog box that says: Hello, We calculated taxes for [number of taxpayers].replace [number of taxpayers] with the actual number of taxpyers you calculated taxes for.

View Replies View Related

Declare Counter With Value Outside For Loop

Mar 29, 2015

Is it possible to declare a counter with a value outside of a for loop?

I have a counter that will end prematurely in a while loop during various iterations and I want to pick it back up in a catch all for loop at the end

Let's say I have a while loop

while(something) {
total++
}

then after I have a for loop that I want to start at total but would rather do that then make a new counter variable.

for(total;total < 20;total++)

Is something like this possible or is this a horrible thing to want anyways?

View Replies View Related

Creating A Button Counter?

Jan 11, 2015

I'm having trouble with my program for my class. The program just has to be able to have a button and show how many times a user has clicked it.

Every time I compile it I get errors such as:

unable to find symbol x where the code is executed when the button is clicked

What can I do?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;
public class Program {
public static void main(String[] args){
int x = 0;

[code]....

View Replies View Related

Counter Method In Java

Dec 28, 2014

i would like to increment variable by one every x ms is there any type of counter method to do so?

View Replies View Related

Making Counter AI For Connect 4 Game?

Apr 28, 2015

I am a student in an intro to computer science class working on my final project. This is essentially a game of connect 4, but only requiring 3-in-a-row for victory. We were given the base game and a sample file to work with to make an AI that beats our professor's ai in the base game. Here is the base game

package cs110.project3;
 import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

[code].....

View Replies View Related

Counter To Count Random Occurrence

Jan 21, 2015

I have 2 classes a main one and another class. In the other class I have a method that has:

String gInfo(){
String[] Behavior = {"Sleeping", "Running home", "Studying", "playing pool", "walking to class"};
int rNum = (int) (Math.random() * Behavior.length);
return Behavior[rNum];
}

I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and how to get it to work correctly.

View Replies View Related

Swing/AWT/SWT :: FPS Counter Only Displaying Ideal FPS

Mar 23, 2014

I have an fps counter in my game loop:

public void run()
{
long currentTime,timeDiff;
prevTime = System.nanoTime();
accumulator = 0;
boolean TRUE = true;

[code]...

When I print the fps variable to the terminal window, it show a value of ~59.9998 - very close to the frameRate of 60. That is to be expected, and works well. The problem is that when I deliberately make the game go really slow, by spamming a bunch of enemies, the game looks slow, but the FPS is still apparently ~59.9998. I thought that maybe the paint() method was not calling when it was supposed to, but that might not be the case.

This FPS counter should be working, I can't see where I have gone wrong. Is there a problem with the code, or is there another problem that might cause the screen to be redrawn 10 times a second with an FPS of 60?

View Replies View Related

Increase Counter When A Post Is Made?

May 15, 2015

I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?

View Replies View Related







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