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>();
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
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);
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.
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));
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??????
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.
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.?!
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, ""));
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
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 ....
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()){
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.*;
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?
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...
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
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.
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.
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?
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 !!
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.
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.