Separating Letters In Text File To Two Different Strings?

May 13, 2013

I have a text file that has the results of rock paper scissors game.

R P
S R
P P

I need to have the first letter in each line assigned to player1 and the second letter in each line assigned to player 2. where to start. I have the file input correct. It is reading the file and I can separate ints from strings. I just don't know how to separate the strings.

View Replies


ADVERTISEMENT

Sorting A Text File With Strings And Numbers

Oct 16, 2014

how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:

blue 18
blue 10
red 27
yellow 4

public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;

[code]....

I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers

View Replies View Related

Assigning Empty Score To Strings In Text File

May 27, 2014

I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:

private void readtextfile() {
try {
Scanner rd = new Scanner(
new File("filename"));
List<String> lines = new ArrayList<String>();
while (sc.hasNextLine()) {
lines.add(sc.nextLine());

[code]...

how to make each of the words to have a score of zero 0?

View Replies View Related

Read Line Of Text And Output Text First In All Uppercase And Then In Lowercase Letters

May 29, 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.

This is what I have so far:

import java.util.Scanner;
public class ShoutAndWhisper
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner (System.in);
System.out.println("Enter the text: ");
scannerObject.next();
System.out.println("The text in all upper case is: ");

View Replies View Related

Reading User-specified Text File Into ArrayList Of Strings Using Java?

Apr 23, 2015

I am advised to use a while loop the Scanner method hasNextLine() and in the while loop body, call the Scanner method nextLine(), and add the returned String to the ArrayList of Strings. what I have gotten so far:

Scanner input = new Scanner(new File(""));
while(input.hasNextLine()) {
String line = input.nextLine();
System.out.println(line);

View Replies View Related

GUI Program To Convert All Lowercase Letters In A String To Uppercase Letters

Mar 21, 2015

Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa.

For example, Alb34eRt will be converted to aLB34ErT.

View Replies View Related

Adding Integers From File But Not Letters

Dec 4, 2014

I have devised a simple program that reads a file and then adds up al the integers in the file and print the result, for example if the file had the numbers
1 2 3 4 5 6 7 8 9 10
then the program would print 55

However i have trouble when non integers are put into the file for example if it was
1 2 3 string 4 5 6 test 7 8 9 10

then i get:

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Week7.Task3.filereader(Task3.java:25)
at Week7.Task3.main(Task3.java:14)

my code is as follows

package testing;
 
import java.util.*;
import java.io.File;
import java.io.IOException;
public class summingInts {
public static void main(String[] args)
throws IOException {
Scanner textfile = new Scanner(new File("intSum.txt"));

[code]....

View Replies View Related

Program That Counts Number Of Individual Letters In A File

Dec 3, 2014

What my program needs to do:

1) accepts a filename from the user that indicates the input file
2)obtains a filename to use as the output file
3)the program then reads the file and reports how many of each letter are there in the file.
4)if the file could not be opened, you must ask the user for valid file name until one is given
5)once a valid file name is given, print all of contents and store the analysis of the file in the output file name specified

You will be reading the input from a file and printing the output to another file. For example, if the file input.txt contains:

This file contains lett3rs.
YoU counT Only lEtTers, not numb3rs.
How many h's are in "Ohhhhhhhhhhh no!"?

The program should ignore white spaces, new lines and other special characters or numbers. It should count only the letters (a-z and/or A-Z) in the input file.

An example execution might look like this:

Input a file name: notAFile.txt
Invalid filename given. Input another.
Input a file name: alsoNotAFile.txt
Invalid filename given. Input another.
Input a file name: input.txt

[Code] ....

1)The last try/catch block was given by my professor, however the only thing it does is print out "hello java" into an out file. How would I make it print out similar to that of the given example?

2)I figured out how to make the array print out ABCDEFG... etc...how to count the amount of them.

View Replies View Related

How To Make A Text File Only Use Lines In A Text File Beginning With A Certain Letter

Mar 15, 2015

I have a program that reads lines of text, but some of the lines of text aren't applicable and break the program. I'd like to put a letter in front of the lines in the .txt file I want to use, such as a #.

I need to make an if loop that'll check for the first letter on the line being #, and use the line in the program if true and skip if false. I'm guessing a boolean variable would be useful here to be true or false depending on the presence of #, but I don't know how to only read the first letter of each line, how can I do this?

View Replies View Related

Separating Digits With Modulus?

Feb 4, 2015

The following code splits an integer into separate digits. It then adds 7 to each of those digits, and then finds the remainder when the result is divided by ten. To do this it uses the Modulus operator.

public class manipulateIntegers {
public manipulateIntegers() {
System.out.println("Enter a four digit Integer");
String y = System.console().readLine();
int[] list = new int[5];

[code].....

I understand completely about what modulus does vis-à-vis fetching the remainder, but I don't understand why using the modulus operator gets you each digit individually?

for example, this snippet splits the digits of an integer - but how??

int number; // = some int
while (number > 0) {
print( number % 10);
number = number / 10;
}

and why does number have to be reassigned as number / 10?

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Enterprise JavaBeans :: Separating Web And EJB Layer And Deploying On Different Servers

May 12, 2013

Web Layer - JSP/Servlets
Business Layer - EJB 3

I want to develop separate projects for web layer (.war) and for Business layer (.jar). I want to deploy these layers on different Glassfish servers.

Here is my Approach -

1. Create a separate module for remote interfaces (.jar), use @remote annotations
2. Create a Web module using JSP/Servlets (.war) and use this remote interface jar in it.
3. Create a EJB module (.jar) and implement these remote interface in it.
4. Use JNDI in Web layer to access the EJB methods.

I want to know if this is the correct approach?

View Replies View Related

How To Delimit Spaces In User Input Separating Two Data Types

Jan 17, 2015

I am creating a calculator in which a user will directly input the numbers and the operator...

Here is my code:

int answer = 0;
int num1, num2;
char operator;
System.out.print("Enter calculation: ");
num1 = kb.nextInt();
operator = kb.next().charAt(0);
num2 = kb.nextInt();

The code above will accept the user input when there are spaces like this: 1 + 1

So the program will give an answer which is 2...BUT

if i input 1+1 it will give an error...Exception in thread "main" java.util.InputMismatchException

How can i do that it will separate integer to character? because i set the operator as character....

So that it will accept one digit to several digit numbers... like 500+84 or 1520+872??

View Replies View Related

Separating Integers Into Individual Digits And Print Separately By Three Spaces Each

Mar 11, 2014

Write an application that inputs one number consisting of five digits from the user, separates the number into in individual digits and prints the digits separated from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each.

For example, if the user types in the number 42339,

the program should input 4 2 3 3 9.

Here is my code so far but I am stuck.

mport java.util.Scanner;
public class Seperating {
public static void main ( String[] args) {
Scanner input = new Scanner(System.in);
int number = 0 ;
System.out.printf("%d" , number );
System.out.print("Enter integer");
number = input.nextInt();
}
}

but I am not getting the result I wanted what am I doing wrong

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

Manipulating Strings In A File Scanner

Feb 25, 2014

I was given a text file that has list of names phone numbers, calls in and out etc... Like this

Adams#Marilyn#8233331109#0#0#01012014#C
Anderson#John#5025559980#20#15#12152013#M
Baker-Brown#Angelica#9021329944#0#3#02112014#C

The # are delimiters between data items and each line has the call status as the last item. I need to know how I can display each persons information on the screen in a format such as:

Name Phone Calls Out Calls In Last Call

Marilyn Adams (823) 333-1109 0 0 01-01-2104
John Anderson (502) 555-9980 20 15 12-15-2013
Angelica Baker-Brown (859) 254-1109 11 5 02-11-2014

I have to use substring method to extract the phone number and add parentheses/dashes ect I also must have a while statement and a delimiter...

So Far my code looks like this Also I am in a beginners Java coding class....

import java.util.Scanner;
import java.io.*;
 public class phonedata2_1 {
public static void main (String[] args) throws IOException {
  String Phonefile, FirstName, LastName;
Scanner PhoneScan, fileScan;
 
[Code] ....

View Replies View Related

Adding Strings To Array And Writing To File

Apr 10, 2015

Every time i try and add a new word to personalDictionary, it only replaces the first index. In my personalAdd method i had tried to add a running count to advance the position it would be saving in but it doesn't seem to be working correctly...

Java Code:

import java.util.Arrays;
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class SpellingChecker

[Code] ....

View Replies View Related

How To Find Whether Strings Contained In Array Of Strings Constitute A Similar Character Or Not

Aug 25, 2014

I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:

aadafbd
dsfgdfbvc
sdfgyub
fhjgbjhjd

my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).

View Replies View Related

Read Txt File And Add Words To ArrayList As Strings - Index Out Of Bounds

Apr 15, 2014

I have been trying to get this method to work for a few hours now, for some reason I get an IndexOutOfBounds exception every time. Basically I am trying to read a txt file and add the words to an ArrayList as strings separated by a space .

private ArrayList<String> readLinesFromFile(BufferedReader inputFile) throws IOException
{
String value = null;
ArrayList<String> result = new ArrayList<String>();
while((value = inputFile.readLine()) != null){
String[] values = value.split(" ");
for (int i = 0; i < values.length; i++){
result.add(values[i]);
}
}
return result;
}

View Replies View Related

Read Text File Into Object Array And Creating Random Access File

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code] .....

And then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19

These continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quantity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Create Random Access File

Dec 9, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code]...

these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Creating Random Access File?

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )

[code]....

and then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34

Mustard Seed,100,64

Coriander Powder,924,18

Turmeric,836,80

Cinnamon (Ground Korintje),951,10

Cinnamon (Ground) Xtra Hi Oil (2x),614,31

Cinnamon (Ground) High Oil (1X),682,19

these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Read Text File Into Array Ask User To Save File And Print Data

Jul 14, 2014

New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows

(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.

[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

[Code]....

View Replies View Related

Creating A System That Will Ask User To Create A File That Will Store To Text File

Mar 9, 2015

I am new to java and I am creating a system that will ask the user to create a file that will store to a text file, Once the user created the file I have a class that will let the user input the subject name that has been created, However, I keep on getting this java.util.nosuchelementexception.Here's my code:

public void display_by_name()
{
String id, name,total;
String key[]=new String[30];
String value[]=new String[30];
int i=0;

[code]....

View Replies View Related

Sorting Lowercase Strings Before Uppercase Strings

Mar 26, 2014

I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.

View Replies View Related







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