Program Won't Scan Properly The Text
Nov 19, 2014
I was trying to do a short program that scans a text for a given word and then tells you how many times that word was repeated in the text. The result was this:
var text = prompt("Write the text to be searched through");
var word = prompt("Write the word to be looked for. Beware of capitals!");
var hits = [];
for (var i = 0; i < text.length; i++) {
if (text[i] === word[0]) {
[Code] ....
However, this doesn't scan the text properly. I think the problem lies in one of the lines from 4 to 8, but, even after thinking quite a lot, I couldn't understand what was it. I thought that by saying that the letter of the text in position [i + k] shuold be equal to the letter of the word in position [k] I could make it work, but it doesn't.
View Replies
ADVERTISEMENT
Mar 4, 2014
I'm scanning my text and I want to add them into array list, but it is not easy. I want each word store from arrayList of a to z which is arrayList size is 26. Example:
arrayList a store string array of: an, and, apple, ...
arrayList b store string array of: be, become, became.....
.
arrayList z store string array of: zero, zone...
In my class, I create:
private static ArrayList<String[]> words = new ArrayList<String[]>(26); // to store all words
In main, I do while loop to get each words and store in words array,
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
public class BinaryTree {
[code]...
View Replies
View Related
Jun 8, 2014
Switching from Swing to JFX 8, I am trying to find out how to do something I would normally do in a super-simple ListCellRenderer, i.e. customize the String displayed for an item. I tried this:
ComboBox<Integer> combo = new ComboBox<>();
combo.getItems().addAll(1, 2, 3);
combo.setCellFactory(new Callback<ListView<Integer>, ListCell<Integer>>() {
@Override
public ListCell<Integer> call(ListView<Integer> param) {
[Code] .....
However, when I do this, the customized String is not used for the selected Item (rather the standard toString() value of the item). Apart from that it is no longer selectable using the mouse (I submitted a bug report for this at [URL] .... but that is not really the point of my question.
Anything else I have to do to make sure the selected item is also rendered using the custom cell or is there a different mechanism for this?
View Replies
View Related
Apr 16, 2015
Why do I get an error on the hasNext line when I try to compile this?
public static void main(String args[]) throws Exception
{
BufferedReader infile = new BufferedReader(new FileReader( "woodchuck.txt" ));
HashMap<String, Integer> histoMap = new HashMap<String,Integer>();
String word;
while((infile.hasNext()) !=null) {
if(histoMap.get(word)==null)
histoMap.put(word,1);
else
histoMap.put(word, histoMap.get(word)+1);
}
infile.close();
System.out.print(histoMap);
View Replies
View Related
May 14, 2014
I am trying to only allow the user to input numbers. But I need to enter a number twice before it moves to the next line statement and also skips a line when i enter th number a second time.
How can I go around fixing this.
My code for this is
case 1:
do{
Event event = new Event();
out.println("Please Enter the name.");
event.setEvent(input.next());
input.nextLine();
[Code]...
View Replies
View Related
May 9, 2010
I am having a problem with my program. I can't get my program to calculate properly. Everything compiles and run but its just giving me a wrong answer. I am suposse to get 115.50 but instead I am getting .30...
order.java
public class Order
{
double salesTaxRate; //initializing a variable for the sales tax rate.
double subTotal; //initializing a varliable for the sub total.
double shippingCost; //initializing a variable for shipping cost.
double salesTax; //initializing a variable for sales tax.
double totalCost; // initializing a variable for totale cost.
[Code] ....
View Replies
View Related
Oct 2, 2014
what weapon the user wants to use and set the element of the Player but I can't use defineWeapon() inside of the constructor so what can I do?here's the player class (where I need to set the element which is the second string in the constructor
package netHackDessart;
import java.util.Scanner;
public class Player extends Monster {
public Player()
{
super("player", "null", 18, 6, 150, 4, 1, 6, 1, 8, 1, true, false);
[code]....
View Replies
View Related
Apr 15, 2014
I want to find a certain element in array I have to scan through the array index starting from 0 until I find the number I am looking for. Even in data structures which use hashing like HashMap and Hashtable we will have to scan through the keys until we find the key we are looking for. So what is the use of hashing over index based searching? I mean how is hashing an advantage over an array?
View Replies
View Related
Nov 1, 2014
I have task for last years in campus , how do you scan document with scanner peripheral in java program? I have browsing on internet, and I have an API like TWAIN.
View Replies
View Related
Nov 5, 2014
I want to write code in java to scan documents.
View Replies
View Related
Mar 24, 2014
I need to create a program that uses ArrayList to store integers the user inputs, then scan the array for the largest number. I would also like the user to be able to exit this loop if the number 0 is entered.
As you can see below, I'm not sure how to correctly exit the do-while loop. I found this on another forum, but it does not work.
Java Code:
import java.util.*;
public class array {
public static void main(String [] args){
ArrayList<Integer> list = new ArrayList<Integer>();
[Code] ....
View Replies
View Related
Dec 30, 2014
I am trying to connect to an oracle rac using jdbc thin . when i use the scan as the host, like this
String url = "jdbc:oracle:thin:@//<scan>:port/servicename;
I get error 1153, connection refused
but when i use the ip of the rac instead of the scan
String url = "jdbc:oracle:thin:@//<ip>:port/servicename;
The connection is successful
Is the issue at the application level? or is the problem with the server ....
View Replies
View Related
May 12, 2015
I am thinking of a project for my university the teachers liked it but I am not sure if its even possible.I am trying to make an andriod app. What I want to do is take a picture of a hand drawn logic circuit (having the AND, OR, NOT ... gates) recognize the gates, and make a circuit in the moblie and run it on all possible inputs.
For this I will have to make a simulator on mobile, that I dont think is the hard part. The problem is how could recognize the gates from a picture. Example of logical circuit is attached ( assume its hand drawn )..I found out that theres a edge detection plugin in java but still I dont think its enought to recognize the gates. Please share any algorithm or any technique or tools that I can use to make this thing.
View Replies
View Related
Apr 13, 2015
package hw9;
import java.util.Scanner;
import java.util.Stack;
public class stack {
public static Integer evaluate(String expression) {
Scanner scanner = new Scanner(expression);
Stack <Integer> operands = new Stack<Integer>();
[Code] ....
When I input my expression which has spaces between characters e.g.:10 2 8 * + 3 -, it worked; when I put expression which may not add space between each char e.g.: 3 14+2*7/, the error showed:
Enter a postfix expression: 3 14+2*7/
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at java.util.Stack.pop(Stack.java:84)
at hw9.stack.evaluate(stack.java:22)
at hw9.stack.main(stack.java:45)
View Replies
View Related
Dec 9, 2014
My assignment is to create a hangman game. One of my first difficulties with it is how to scan the string for an input supplied by the user.
Here is my method:
//Guesses that character c is in the secret word.
//Updates all instance variables accordingly,
//and returns true if c is present in the secret word.
public boolean guessCharacter(char c){
}
View Replies
View Related
Jun 2, 2014
Write a program that reads in a line of text and then outputs that line of text first in all uppercase letters and then in all lowercase letters.
INPUT and PROMPTS. The program prompts for a line of text as follows: "Enter the text: " and then reads in an entire line of text as a String .
OUTPUT . There are four lines of output . The first line is "The text in all upper case is: ". The second line is the line that was read in, displayed in all uppercase. The third line is "The text in all lower case is: " and the fourth line is the original line that was read in, displayed in all lowercase.
CLASS NAMES. Your program class should be called ShoutAndWhisper.
[import java.util.Scanner;
public class ShoutAndWhisper
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner(System.in);
[code]....
View Replies
View Related
Feb 18, 2014
I'm using NetBeans.
I have a JFrame with four JPanels, SensorLL, SensorLC, SensorCR and SensorRR. They are instances of the class SensorUI. Each has a JLabel called Sensor.
The class SensorUI has a method writeSensor that writes to the JLabel "Sensor". I will have four temperature sensors. I have not started the code to read the temperature sensors yet. I will have a timer that will run once a second. When it fires I will read the sensors and display the result in the
JLabel "Sensor" in each jPanel.
I use MyMain to call FrameDemo and create the JFrame and a method
in FrameDemo to add the JPanels using addObject.
I can use SensorLL.writeSensor will write text to JLabel Sensor while in Mymain.
Then I start the timer ReadSensor.
When it times out it calls SampleSensors
For an experiment, while in SampleSensors I try to write to the JLabel in the instance SensorLL with
SensorLL.writeSensor("xx_");
I can't because it says it can't find the symbol variable SensorLL in SampleSensors class.
How can I "get to" that JLabel text when ever I need to?
Java Code:
public class MyMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//SensorUI SensorLL = null;
System.out.println("Start of main");
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
FrameDemo.createAndShowGUI();
[Code] .......
View Replies
View Related
Apr 29, 2014
I'm working on a project for my Java class and I've got the code compiled and running, I just don't think that the program is reading the text file the way I want it to.
The text file looks like this:
1168,4.25,10
1305,1.80,42
1345,12.56,16
1388,7.42,30
1480,6.54,80
1495,8.36,48
1560,15.27,65
...
The first number being product number, second being price, and 3rd being quantity. I want to be able to enter the product number and have the Textfields for price and quantity be filled accordingly.
But when I enter a product number (e.g., '1168') no match for the item is being found, regardless of what I enter. Really stumped on this. Here's my code so far --
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Scanner;
public class Project3
{
private static Frame myframe;
private static TextField productCode;
private static TextField invNumberField;
[Code]...
View Replies
View Related
Jan 18, 2014
I want a java program to find the language of a given text in a program
For Example: If user enters Hello World it should say its english language
And if he enters a spanish language as a input it should say its spanish language and so on....
View Replies
View Related
Sep 21, 2014
I'm trying to copy my program output to a text file and still have it be displayed in the console.
View Replies
View Related
May 13, 2015
This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....
Here is the code..
package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
[Code] .....
View Replies
View Related
Aug 5, 2014
I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.
I am using java 1.7 sdk and pupy linux as OS. Below i am giving source code.
What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.
But what is happening is it shows welcome text and then directly Plzz wait..
Its not showing text Enter... because control is finished after last method gets executed.
My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.
public class BackgroundFrame extends javax.swing.JFrame {
JLabel setTitle1;
JLabel setTitle2;
JLabel setTitle3;
JLabel setTitle4;
[Code] ....
View Replies
View Related
Mar 19, 2015
I was wondering if it's possible to do this: I want to build a java program that reads a java array from a text file.
Then I want to read it, and output it in a different format.
The reading and out is easy - as text.
But how can I incorporate the read text in to a java valid array in my program, which I can use?
Is this even possible?
View Replies
View Related
Apr 14, 2014
I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.
View Replies
View Related
Feb 12, 2015
This has three different classes in a package and the program itself is supposed to read and perform operations obtained from a txt file. However, I'm not even sure how to get it to perform the operations from the text file. I know that it can read the file as I was able to get the program to print the text found in the file when I ran the program with a test print to make sure that all content was being read. However, I am clueless when it comes to how to get the program to look at the text as commands.
Here is the piece of code that I am not sure where to go from as far as telling the program to read the text and perform the tasks listed.
public static void doTVoperations(){
File operations = new File("operations.txt");
if(operations.exists())
try{
Scanner n = new Scanner(operations);
while(n.hasNext()){
String readOperations = n.nextLine();
String [] command = readOperations.split("[
]");
}
n.close();
}
catch (FileNotFoundException e){
System.out.print("Error...TV in need of repair!");
}
View Replies
View Related
Dec 23, 2014
I have been writing the below Dinner Menu Applet; however some text is not showing on the applet and it is not adding the 'desserts" section correctly especially the one that says "rice Pudding". I've tried it in so many different ways and it's sill not working correctly.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class DinnerMenuApplet extends Applet implements ItemListener
{
Label dinnerMenu = new Label("Dinner Menu");
[code]....
View Replies
View Related