Reading From TXT To ArrayList?

Nov 21, 2014

I am currently working on a program that will read from a .txt file to create an arraylist. I will be working with the objects in the list to perform computations and display the data. The .txt file is in the following format: lastName firstName hoursWorked hourlyRate

With no delimiters. I've messed with this thing way too much in the last 12 hours (only day off for the week ) so variable names etc have changed often. At present the error I am receiving is "error: constructor GrossPayService in class GrossPayService cannot be applied to given types".

import java.util.*;
import java.io.*;
import java.text.*;
class AryListObjects
{
public static void addEmployee(String firstName, String lastName, double hoursWorked, double hourlyRate)
{
ArrayList<GrossPayService> employees = new ArrayList<GrossPayService>();

[code]....

View Replies


ADVERTISEMENT

Reading File And Store It In Arraylist

May 25, 2014

i have to read a file and then store that file in an arraylist. i have 2 clasees, a pyramid and a cylinder class and the file contains unorganized shapes. i want to store all of them in the array but my code does not return anything

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;

[Code].....

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

File Reading Values To Draw Image (java Graphics DrawString / ArrayList / Array)

Sep 13, 2014

//compiler error I'm receiving
J:CS3Student Folder Review Lab #2APlusImage.java:41: error: cannot find symbol
xcor.add(read.nexInt());

[Code].....

View Replies View Related

Create Own ArrayList Using Collection Without Implementing ArrayList Itself

Feb 28, 2014

I'm trying to create my own arraylist using Collection. My program doesn't do anything. Obviously, I haven't a clue.

import java.util.Collection;
import java.util.Iterator;
public class MyArrayList<T> implements java.util.Collection<T> {
private int size = 4;
private T[] mArray;
public MyArrayList(String[] args) {

[Code] ....

View Replies View Related

Populating ArrayList Object With Nested ArrayList Object

Jul 8, 2014

I have stumbled onto a problem with ArrayLists (not sure if nested ArrayList objects would be a more accurate description) ....

As simply put as I can describe it, I have an Inventory class which creates an ArrayList of a Product superclass, which has two subclasses, PerishableProduct and ItemisedProduct.

By default, the program is meant to have a starting inventory, which is why I have added them in the constructor

public class Inventory {
private List<Product> products;
public Inventory() {
addProduct(new Product("Frying pan", 15, 20));
addProduct(new PerishableProduct("Apple", 5.8, 30, 7));
addProduct(new ItemisedProduct("Cereal", 5.8, 0));
// this is where I am having problems. Wanting to add
// objects to the ItemisedProduct's ArrayList for cereal.
}

Within the ItemisedProduct subclass is yet another ArrayList which is meant to hold serial numbers.

public class ItemisedProduct extends Product {
private ArrayList<String> serialNumbers = new ArrayList();
public ItemisedProduct(String name, double price, int qty) {
super(name, price, qty)

[Code] .....

My problem is that I do not know how to populate the serialNumbers ArrayList from the Inventory class' constructor. Because technically, quantity is defined by how many serial numbers are created.

View Replies View Related

Reading Only First Name From Strings?

Feb 12, 2014

I know that in c++ in order to read a string like

PHP Code:

. you need to use

getline(cin,string variable)

. In java, I have noticed that using

String name=keyboard.nextLine()

automatically reads the whole line...Suppose I wanted to read the first name only, how would I be able to accomplish that?

View Replies View Related

Reading PDF By Using Java

Feb 5, 2014

i am reading pdf through java and write that data in .csv file.problem is like that when i read 500 pages from pdf at that time they can write only 496 lines what can i do for that i can read all 500 pages from the pdf .my code is like..............

public class pdf1 {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
try {
PdfReader reader = new PdfReader("me1.pdf");

//int n = reader.getNumberOfPages();
File outFile = new File("b.csv");
int n=500;
int count=0;
BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));

[code]....

View Replies View Related

Reading CSV File

Jan 18, 2014

I have a CSV file with 16K entries of a data table. Does Java work well with CSV file? So I found this code. And it seems its quite easy to read in the data I need. Say for example if I wanted a loop to randomly pick the first field of a specific line in the CSV data table. How would i go about coding that??????

package cvs.test;
 
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
 
[code]....

The CSV looks like the above. and I basically would like to read in the Hand to get it to show in a text box and then randomly have the program ask me to correctly identify the True/False return for one of the SB/BB/UG/MP/CO/BN columns.

View Replies View Related

Reading XML Document From Web?

Aug 12, 2014

How could I read an XML document from the web? I've seen people use SAX or DOM methods, but I've unable to make them work due to lack of experience so I would need a pretty brief overview not just 2 bits of code without any imports etc.

Also how would I be able to COMPARE the information? Like if it's " Sunny " I set a label text sunny etc.?!

I'm trying to read this : [URL] .....

View Replies View Related

How To End Reading From Console

May 21, 2014

This is my program. All is working fine except stopping reading from console. Problem is that even after you write done if you are fast enough you are able to write more. As you can see I can't close scanner because of two inputs. Even so I tried to close it but problem was still here.

public static void main(String...args) {
System.out.println("Write first input:");
System.out.print(streamToString(System.in, ""));
System.out.println("Write secondinput:");
System.out.print(streamToString(System.in, ""));

[Code] .....

View Replies View Related

Substrings And Reading In Files

Feb 6, 2015

I know that I need to use substrings, but I'm not sure how to implement them. All of the names are red in from the file "employees.txt".

Using the file Employees.txt

1) Scan the file and create user ids for each person according to the following scheme

a) Take the first and last character of the first name, convert them to upper case

b) Take the first and last character of the last name, convert them to upper case

c) Concatenate the results from a and b
i) Example: John Brown would yield => JNBN

d) Add the length of the first name to the length of the last name, disregarding spaces

e) Concatenate the result from step c to the result of step d
i) Example: John Brown would yield => JNBN9

f) Concatenate a four digit number to the end of this.
i) The numbers should begin with 0000 and increment by 1
ii) Example: If John Brown is the fifth name in the list the resulting UserID would be => JNBN90004

2) Display the user ids in four columns with a width of 14

View Replies View Related

Reading A File Header / Hex?

Mar 3, 2013

how to get the first few hex symbols of a file in java, for example if i input a pdf into my coding i want my program to output, e.g "25 46 44 38" ....

I have been able to print out the hex of a whole file but not managed to set a maximum read limit so that my code only takes a certain amount of values ....

View Replies View Related

Reading Only Integers Not Text?

Feb 19, 2014

my code is below and i want to read only integers.BUT the text file is starting with text and it stops executing without reading the numbers.Also i want to add the 3 parameters of each line.

try{
File fl = new File("C:/Users/Mario/Desktop/testing.txt");
//BufferedReader rd = new BufferedReader(new FileReader(fl));
Scanner sc = new Scanner(fl).useDelimiter("s+");
LinkedList<Integer> temps = new LinkedList<>();
sc.useDelimiter(System.getProperty("line.separator"));
  while(sc.hasNext()){

[code]...

View Replies View Related

Reading 1 Column And Printing

Oct 6, 2014

i have to read a text doc that has 149392014080186 (station# year/month/day temp) many more following but i have to read the temp and determine if it is under 80 degress my code so far is the second scanner reads the text file i need the 1st scanner reads the user info

/******************************************************************************
*
* Filename : ClimateSummary.java.
* Description: This program computes summaries of climate data and reads if it is rainy/not rainy or cold/hot.
*
******************************************************************************/
//imports everything needed to run the program
import java.util.Scanner;
import java.io.*;

[code]....

View Replies View Related

Getting Progress Of Reading Disk?

Oct 16, 2014

I have this method:

Java Code:

public static void listFiles(String path) {
File[] list = null;
File root = new File( path );
list = root.listFiles();
if (list == null) return;
for (File f : list) {
if (f.isDirectory()) {

[code]....

How would I get the overall progress of reading the directory I give to it, for example, if I give it the root directory of my computer, it would read through ALL my files and folders, and that works fine.But how would I get progress for a progress bar?

View Replies View Related

Reading And Writing Wav Files

May 17, 2014

I have copied a wav file as explained in [URL] ..... When trying to play my new file, it runs but no sound is hear. My reading and writing class is as explained in another post in the site:

This is the function that reads the file:

// read a wav file into this class
public boolean read(DataInputStream inFile) {
myData = null;
byte[] tmpInt = new byte[4];
byte[] tmpShort = new byte[2];

[Code] ....

I can't hear the copied wav file, but still the wav file is correctly copied...

View Replies View Related

BNF Grammar And Reading From A Txt File?

Mar 21, 2014

I am implementing a recursive descent parser that recognizes strings in the language below. The input should be from a file "input.txt" and output should be to the console.

The grammar:

A -> I = E | E
E -> T + E | T - E | T
T -> F * T | F / T | F
F -> P ^ F | P
P -> I | L | UI | UL | (A)
U -> + | - | !
I -> C | CI
C -> a | b | ... | y | z
L -> D | DL
D -> 0 | 1 | ... | 8 | 9

An example session might look like this:

String read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language.

String read from file: a=a**b++c

The string "a=a**b++c" is not in the language.

Java Code: /**

* The Grammar
* A -> I = E | E
*E -> T + E | T - E | T
*T -> F * T | F / T | F
*F -> P ^ F | P
*P -> I | L | UI | UL | (A)
*U -> + | - | !

[code]....

My current output looks like this:

Java Code: The string read from file: a=a+b-c*d

The string "" is not in the language. mh_sh_highlight_all('java');

So it seems to be reading the input file correctly. My error seems to be on this part

Java Code: s = args.length == 1 ? args[0] : ""; mh_sh_highlight_all('java');

When I put the string in that line such as: s = args.length == 1 ? args[0] : "a=a+b-c*d";

My output is:

Java Code: The string read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language. mh_sh_highlight_all('java');

How can I go about it reading the string from the input file though?

Also, I am not too sure my boolean functions for P, I and, L are correct. Mainly when two terms are together (UI, UL, CI, DL).

View Replies View Related

Reading Content From FTP File?

Jan 27, 2013

I am trying to read a content of file downloaded from ftp and return it as a String. This is what I use:

Java Code:

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;
public class Test {
public static void main(String [] args) throws IOException{
FTPClient ftp = new FTPClient();

[code]....

The code does not work, although all the links are correct.

View Replies View Related

Reading Number Of Points

Oct 24, 2014

I am trying to receive an input file which has either 6 or 8 points and whether it is 6 or 8 points, I do ask the program to save it into an array and then print it. However my program crash after printing few lines. I do know what is wrong with the program my line.split(",").length print 1 at the first and then start printing the numebrs in teh rest of lines which makes it skip a line which means the lines that has for example 8 points will go to a loop that only 6 points and a line that has 6 points will go to a loop that has 8 points and then obviously crashes.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;

[code]....

View Replies View Related

Reading From Standard Input?

Jun 20, 2014

I have to write sorting algorithm for numbers given on standard input(console) with following requirements:

The application must remember the distinction between double and integer numbers. This must be evident in the sorted output. Double type numbers are written using a period (.) to separate the fraction from the whole part.

The problem is I don't know how to efficiently distinct whether something is an int or double on standard input, to save them into 2 different arrays.

Only idea I've come to so far is to read each number as String and check if it has '.' character, to figure out if it's double and than convert it into right type and add it to correct array.

Also thought that maybe this would be achieveable using Pattern but how to do that?

View Replies View Related

Reading From A File - While Loop

Oct 22, 2014

I have to read from a file that is formatted like that :

name
status
friend
END
name
status
friend
END
.. etc

could be more than one line of friends, which where I have my problem. I can't get it to check if after the friend name the word "END"

I have tried to write a while loop inside the main while loop but it didn't work, and now I have tried to check that in a separate function which it also failed, thats my two while loops

BufferedReader br = null;
FileReader fr = null;
int getLine = 0;
try {
String line;
fr = new FileReader(fileName);
br = new BufferedReader(fr);

[Code] .....

Most of the time I got nullPointerException or missed up order for printing the file !!

View Replies View Related

File Reading / Writing

Sep 9, 2014

I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.

View Replies View Related

Reading Values From The Keyboard?

Aug 21, 2014

why we are not able to read second string in this program.

String s1,s2,s3;
String decider;
Scanner sc = new Scanner(System.in);

[Code].....

Note: If I uncomment line num 9 it works fine

View Replies View Related

Reading A Nested For Loop

Nov 5, 2014

for (int i = 0; i < 4; i++)
{
for (int k = 0; k < i; k++)
{
System.out.print(" ");
}

for (int j = 4; j > i; j--)
{
System.out.print("$");
}
System.out.println();
}

I was told that the answer when this code segment is printed look's like this:
$$$$
$$$
$$
$

Here's what I did:Looking at the outer for loop, (i) 0 < 4 so I went into the first inner nested loop. (k) 0 is not less than (i) 0 so I went to the 2nd inner nested loop and found that it worked, and I was able to repeat this loop 3 more times and then I exited the loop and printed the line out (giving me the first line of four $). I then went back to the outer for loop, increased i by 1 and (i) 1 < 4 so I went to the 1st inner nested loop. I used the 0 for the k first and (k) 0 < 1 so I printed out a space (now here's where I get lost) I then incremented k by 1, so k = 1, but 1 is not less than 1 (i) and so I moved on to the next nested for loop. So when this line is printed, I'll only have one space when there should be 4.

View Replies View Related

Not Reading Entire File

Mar 29, 2014

I'm new to Java and have not been able to figure this out. I'm reading a text file that contains this:

110001 commercial 500000.00 101
110223 residential 100000.00 101
110020 commercial 1000000.00 107
110333 land 30000.00 105
110442 farm 200000.00 106
110421 land 40000.00 107
112352 residential 250000.00 110

The output goes to a text file and should look like this:

COMMERICAL

FARM
LAND
RESIDENTIAL

101 600000.00
105 30000.00
106 200000.00
107 1040000.00
110 250000.00

I'm creating the output file, but it only contains the categories and not the details below them. Cant seem to figure out why.

Java Code:

package propertylistings;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

[Code] ....

View Replies View Related







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