I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .
I am unable to post my code, it redirects me to a 'Page not found' page.
The problem with my program is a variable that I have initialized, is being said its not being initialized.
I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .
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.
I am having some trouble with a Java program. I have a txt data file, which I will display, that I need to add into two separate arrays. The text file is 8 lines long that is supposed to go into two separate 4x4 matrices. A little background info on this program, reads in two arrays, compares them and outputs the largest elements of the same index and outputs them in a separate array. I somehow cannot seem to figure out how to do this. My code is below:
I am supposed to read in a file and extract the data. I am trying to add a Long into an Array that I initialized. So this is how my method looks like :
Java Code:
public void readOSMWay(File osm){ try { Scanner output = new Scanner(osm); while(output.hasNext()){ String line = output.nextLine().replace("^s+",""); if(line.startsWith(" <way")){ Road way = new Road(line,true);
[Code]...
I am having problem with the else if block. I am supposed to add all the Long values into the array.
error: Java Code: The method add(Long) in the type ArrayList<Long> is not applicable for the arguments (String) mh_sh_highlight_all('java');
"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."
I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".
This is the code of Product.java that came with the exercise.
public class Product { private String productCode = ""; private String productName = ""; private int quantity; private String supplierName = ""; private String supplierAddress = ""; private double price;
[Code] .....
By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:
54643 Rizer Mouse Mark5s Merchandising Marquee Mall 4 205.50 23412 Acer Ultrabook JohnJade Merchandise Cornal City 2 62200.00 93112 Dell Ultrabook Octagon Marketing Cornal City 3 68900.00 22126 Macbook Air Pro Computerware Services San Beda, Chad 2 93500.00
I am developing a java code using netbeans for encryption decryption by RSA algorithm. Swings and file handling play a major role in these code. My encryption code is working nicely but the code for decryption is not since keys file is not being read. That is why variable mod and pri are getting null values and the following error stack is coming. I know where the problem is somewhere in void readkeys() function but cannot solve it.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.math.BigInteger.modPow(BigInteger.java:1579) at rsakeydecryption1.RsaKeyDecryption.decryption(RsaKeyDecryption1.java:167) at rsakeydecryption1.RsaKeyDecryption.read_output(RsaKeyDecryption1.java:294) at rsakeydecryption1.RsaKeyDecryption.actionPerformed(RsaKeyDecryption1.java:330)
Pass each index each time to a method returning all rows but getting stuck with DS to use. I think ArrayList wont suffice since i need separated data. Should i use a 2D array? Do i need to read and store data in a DS in order to achieve the goal?
2) Should i make 3 different classes with getters and setters for authors, book and magazine?
I have a random access file stream. I have below code I want to written data that is currently pointed by pointer till the end and display that data on System.out Stream but it is not working my code is
//Create a Random Access File java.io.RandomAccessFile random=new java.io.RandomAccessFile("D:/input.txt","rw"); //Position the pointer to a seek try { random.seek(300); long pointer=random.getFilePointer(); System.out.println("Current Pointer is:"+pointer); int a; while((a=random.read())!=-1) { System.out.println(a); }
Where am I wrong? Although it is returning actual position of pointer in pointer using
I need to read a csv file from the disk and manipulate the data inside. My problem is that if the csv (excel format) contains "" in any of it's values the whole string line gets saved/displayed incorrectly . For example for the line in the csv file :
I'm trying to figure out the necessary code for reading integers from a text file, then placing them withing the two-dimensional array I have created, and then finally printing the array using a nested for-loop. I have attached the file I would like to read from. I'm having trouble figuring out how to reference the text file with the integers, and also how to properly create a dynamic preface for each row of the array. I want the preface to display as "Week #: ", with # being the row number. I tried to create an integer to be used that way, but NetBeans tells me whatever integer I declare has already been defined in method main. I know I need to use scanner to read the file. I would like the output to display like this:
I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)
1 FOR SALE: Emmalaan 23 3051JC Rotterdam 7 rooms buyprice 300000 energylevel C
The user gets (let's say for simplicity) 3 options:
1. Add a House to the file, 2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and 3. Close the application.
This is how I start:
Scanner sc = new Scanner (System.in); while (!endLoop) { System.out.println("Make a choice); System.out.println("1) Add House"); System.out.println("2) Show Houses"); System.out.println("3) Exit"); int choice = sc.nextInt();
Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).
For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)
If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).
My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this
I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code
import java.io.*; import java.util.*; public class prog464aStoringLargestNums { public static void main(String[] args)
I am now stuck. I am writing a program that reads information from a data file and runs it through but program. However, I am almost finished with the program, but cannot figure out the last few parts.
public class Storm { private final double KnotsToMPH = 1.15; // global user-defined types: private int beginDate; private int duration; private String name;
[Code] .....
I have not attached the data file because it contains a total of 360 lines of hurricane information.
i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..
I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt Displays Data with calculation Creates a file called "Newbalance.txt" with the following values:
111 251.41 222 402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*; import java.util.Scanner; import java.text.DecimalFormat; public class Output { public static void main(String[]args) throws IOException {
I am working on my second javafx program and I am getting confused. The program that I am writing is a payroll calculator. A secondary window opens at the start of the program where the user first enters the number of employees and clicks submit to save the number and to close this window. Then, the user begins to enters the employee information (first name, last name, pay rate and hours worked) when the user clicks the NextEmp button, I want the data in the text fields to be entered into arrays for later use, then clear the fields for the next use. I am running into 2 issues. The first is the close event for the secondary window that pops up. I cannot figure out the syntax. The second issue that I am running into is the loop to store the data into the arrays. I believe I am getting the text field data correctly, but I cannot figure out how to stop the loop until the NextEmp button is pressed again.
I am just learning arrays or rather teaching myself about them and I am not to sure how they work and why. I understand that in order to set one up you do
int[] example1; example1 = new int[]{01, 02, 03, 04};
But I don't really understand is why if you only need 3 data integers, why put the 4th one in?
Also with outputting data, I understand .print() and .println() but I am not to sure what .printf() does and then the formatting after that.
System.out.printf("%3d%11") // and then what you want to print
The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file: Pairs.txt
Which contains the data for each pair of skaters. The data consists of each skater's name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows:
Smith Jones Australia 5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8 4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5
The final score for each skater is the sum of the average of the two categories of score. Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners.
Here is my CLass:
public class Skaters { private String name1; private String name2; private String country; private double [] arrTech = new double [8]; private double [] arrArt = new double [8]; private double score;
[code]...
how do i print my 2 arrays using the file? i got the name1, name2 and counntry to print but im stuck on printing the scores that are stored in the arrays. Also, i have to print the average for each array. one is for techniques and the other one is artistic. as you can see i already wrote the code for it but im stuck in printing it.
My friends and me are trying to make online Test taking system. We got a very basic doubt.
We have developed classes and relationship between classes for example : Online Test Taking system will have admin and student class. And Admin will have list of students.. etc.
But question troubled me was: if we use database to store all data for example student details then I can perform all sorts of operations writing sql query and store result in some other database then what is the need of "ArrayList<Student> field in Admin".??
Question is: We can put everything in database and manipulate using database(sql) functions to manipulate it.Then what is the need of Arraylist of anything which is just used to store object details for example student details....??
I have the following code which reads in data from a bluetooth transmitter, however the program is crashing upon read-in. The bluetooth connects to the device just fine, as indicated by the indicator LED on the transmitter. However during the read-in:
void beginListenForData()
is where the exception happens. Specifically, it is at the line
readBuffer[readBufferPosition++] = b;
However I don't know why it is crashing. My transmitter is sending 1 byte (0x02) at 9600 baud every 1 sec for testing purposes.
I need getting detailed examples about how I can read/insert into database using JSF code for its different components. I am a beginner in JSF and I have the basics, however, I need the best source which it has useful, easy and detailed steps to understand the techniques for connecting to the DB and how to insert or read data from the database.
I tried to search, but I found the lessons are not useful or not described in details.
I am trying to write a program that read from a csv file called matches.csv.
A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case of draw each of the two teams get 1 point.
For example, the first line of the file matches.txt is as follow:
This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points.
How can I structure my output to make it make it read
Position Team Played Points 1 Aston Villa 2 3 2 Liverpool 1 3 3 Arsenal 1 0
import java.io.File;
import java.io.FileNotFoundException; import java.util.Scanner; public class Teams { public static void main(String[] args) { String fileName = "matches.csv"; File file = new File(fileName);
I am trying to write a program that read from a csv file called matches.csv.
A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case of draw each of the two teams get 1 point.
For example, the first line of the file matches.txt is as follow:
In the file it contains the following data.
17/08/2013 Arsenal Aston Villa 1 3 24/08/2013 Aston Villa Liverpool 0 1
This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points.
How can I structure my output to make it make it read
Position Team Played Points
1 Aston Villa 2 3 2 Liverpool 1 3 3 Arsenal 1 0
Java Code:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Teams { public static void main(String[] args) { String fileName = "matches.csv";
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.
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.....