Adding Data File Into Two Separate 2D Arrays In Java

Apr 27, 2014

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:

Data File:

2 7 6 4
6 1 2 4
9 7 2 6
8 3 2 1
4 1 3 7
6 2 3 8
7 2 2 4
4 2 3 1

Code:

public class prog465a {
public static void main(String[] args) {
Scanner inFile = null;
try {
inFile = new Scanner(new File("prog465a.dat.txt"));

[Code] .....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Java GUI With Separate Class For JList - Adding Items To The List?

Sep 19, 2014

I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.

Here is my code:

//Main class
public class TestProject {
public static void main(String[] args) {
GUI mainWindow = new GUI();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[Code] ....

When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.

View Replies View Related

Reading Data From A File And Putting That Data In Arrays

Feb 8, 2015

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 .

Java Code:

public static void main(String[] args) {
// TODO Auto-generated method stub
// Variables Declaration Section
//******************************
BufferedReader br;
String sCurrentLine;
String str;

[Code] ....

My issue is that the 'str' value is not initialized, but if I initialize it, it ruins the code. I'm not sure what to do in the situation.

View Replies View Related

Compare Two Different Arrays From Separate Loops

Oct 21, 2014

I am working on an assignment that is to simulate the relationship between a cache and main memory. Basically it is supposed to be a 16 slot cache and we are to have 500 for main memory. I need it to compare the corresponding index for both arrays, then go through then repeat the cache array and compare it to the next 16 of main memory. It is to simulate an direct mapped cache. How to compare two arrays from separate loops.

public class MainMemory {
private short mainMem[] = new short[200];
public void assign(){
short i;
for ( i = 0; i < mainMem.length; i ++){
mainMem[i] = i;

[Code] .....

View Replies View Related

Data Read From File And Being Placed Into Arrays

Feb 8, 2015

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.

View Replies View Related

I/O / Streams :: Does Printwriter Always Truncates Existing File To 0 Size Before Adding Any New Data

Jun 13, 2014

Does printwriter always truncates the existing file to 0 size before adding any new data ??

View Replies View Related

Java Class Person - Adding Data To Text

May 5, 2014

Your Tester class main method must use an array or an ArrayList of Person objects. It must be populated from a text data file, friends_data.txt. Add the following data to your text file,

Michelle, 12/20/2008, Camilla
Bryan, 3/8/2007, Tom
Camilla, 6/7/2005, Michelle
Tom, 10/15/2007, Bryan
Charlotte, 3/2/2008, Michelle

Each line has the meaning:

-Person name, Person date of birth (MM/DD/YYYY), name of best friend
-Write a Java program that reads in the data from the friends_data.txt file, allocates a new
-Person for each and then stores the newly created object in either an Array or an ArrayList.
-Next print out a report showing the following information for each Person,

1. The Person's name
2. Their popularity counter
3. Their age on May 1, 2014
4. The name of their best friend
5. The age of their best friend on May 1, 2014

Finally, print the name of the most popular Person and the name of the oldest Person.

Person Class

import java.util.ArrayList;
public class Person {
public String personsName;
public String personsFriend;
public String personsBirthday;
public int personsPopularity;
public int popularity = 0;

[code]...

I keep getting this error from the compiler:

System.out.println("Popularity : " + personsOfInterest[i].getPopularityNumber());

"method getPopularityNumber in class Person cannot be applied to given type:
Required: java.lang.String[]; found: no arguments; reason: actual and formal argument lists differ in length.

View Replies View Related

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.

[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);

[Code] .....

View Replies View Related

Logging In Separate File

Oct 14, 2014

in log4j,in a web aplication i need loging in separate file,logging for action package in one file and dao in another file in action package log a class if this is possible in a class then a level in a file another level in another file.

View Replies View Related

Adding Java Program To Windows Startup Using Bat File

Jan 19, 2015

I've added a small program that reads from a .txt file to the windows 8 startup folder using a .bat file ... The problem I have Is I've used relative paths for text files In the program and It doesn't work unless I change them to absolute paths.

The .bat file Is basically java -cp[absolute path to program directory] ReadAFileApp . Is there something (most likely yes!) I'm missing here ?

View Replies View Related

Reading From A Separate Config File

Jul 30, 2014

I am trying to create a bukkit plugin. I need to be able to read from a separate config file but do not know how.

I am trying to use a JSON parser to read from a file but I only need a specific line of the file. Would this work?:

JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader("/plugins/easyRace/config.yml"));
JSONObject jsonObject = (JSONObject) obj;
String Races = jsonObject.get(var "Races:");

View Replies View Related

JavaFX 2.0 :: Pop Up Using Separate FXML File

Feb 23, 2015

I have created an application in SceneBuilder, and want to call a pop up (also created separately in scene builder) when a certain button is pressed. How?

View Replies View Related

How To Separate Numbers In A File And Put Leading Zeros

Nov 15, 2014

I am writing a program that adds together large integers. I have to store each integer in an array of digits, with one digit per array element. Array length is 50 so integer is 50 digits long. I have to store numbers in right-shifting format with leading zeros. For example,

0000000000000000000038423
0000000000000000000000027

Sum.txt contains numbers to be added. There could be one or more numbers per line.each line must be read as string with next() since it's assumed to be a very long number. String of digits needs to be converted into an array of 50 digits. Method CharAt and Character.getNumericValue will be useful. All numbers in each line are to be added. There are no negative numbers and individual number might be 0 or answer might be 0. Answer is always 50 digits or fewer.

BigDecimal or BigInteger are not allowed.

I'm lost where it says to put number with leading zeros in a 50 room array. How do I add numbers after formatting numbers with leading zeros?

View Replies View Related

I/O - Read 11 Values From A Text File / Each Value On Separate Line

Mar 26, 2014

So I'm trying to read 11 values from a text file, each value on a separate line. The first value I use as loop control to run through calculations on the other ten and finally output both the numbers and the calculations to the console and an output file. I'm not getting a compiler error or a runtime error but my loop seems to stop after reading the first line. It also doesnt seem to be writing to my output file but does create it when I run the program. This is what my text file looks like

10
150.4
88.4
-3.14
499.4
799.4
1299.8
0
1900.2
901.7
4444.4

This is what my program looks like

import java.util.*;
import java.io.*;
 public class assignment7scratch
{
  Toolkit_General toolKit = new Toolkit_General();
  public static void main (String[]args)throws IOException

[Code] .....

so I dont get an error but this is what my output looks like

----jGRASP exec: java assignment7scratch

This program reads a list of values representing number of miles driven by individuals. It will output the dollar amount their rental cars cost.

Number of miles traveled on the left as well as amount reimbursed on the right

-----------------------------------------------
Miles Driven Amount reimbursed
150.427.072

----jGRASP: operation complete.

it also doesn't write anything to my output file, though it does create one.

View Replies View Related

Can Use Java Code From OpenScript Or APIs In Separate Java Program?

Oct 24, 2014

I want to develop a Java program that uses OpenScript APIs to test my applications. The OpenScript framework automatically creates the Java Code so I was thinking of either using this code or create my own using the APIs.
 
I tried both options using NetBeans but I'm getting errors everywhere starting with the library import. I'm pretty new to Java so I'm sure I'm missing a lot of things here. I pasted the code below from the OpenScript framework that want to use in a stand-alone file for your reference.,
 
import oracle.oats.scripting.modules.basic.api.*;
import oracle.oats.scripting.modules.browser.api.*;
import oracle.oats.scripting.modules.functionalTest.api.*;
import oracle.oats.scripting.modules.utilities.api.*;
import oracle.oats.scripting.modules.utilities.api.sql.*;

[Code] ....

View Replies View Related

Communication Between Two Separate Java Program In Same Computer

Sep 20, 2012

I have two separate java Program that run on the same
computer : Program -1 & Program-2 .

Explain Program-1 :

Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .

Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .

This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .

I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .

View Replies View Related

How To Write Java Data To Pdf File

Apr 9, 2014

how to write java data to pdf file

View Replies View Related

Looping Through JTextFields And Storing Data In Arrays

Aug 6, 2014

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.

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.input.KeyCode;

[Code] .....

View Replies View Related

Arrays And Formatting Output - Data Integers

Jan 23, 2015

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

View Replies View Related

Java Code Removed Data From XML File

Jul 16, 2014

I tried working with XML today, since that's what my book teaches. First, I read some data about Product objects that are suppose to represent products with a code, description, and price. That worked fine. Then, I tried creating a writeProducts(ArrayList<Product> products) method, and man it did not go well.

How it works is that there is an ArrayList instance variable in the class that keeps track of all of my products after the readProducts method returns that ArrayList from the XML file. When I ran the method I had a lot of stack traces printed. I then checked the file on a web browser and an editor, and saw it was completely empty. Here's the code:

import java.util.ArrayList;
import java.io.*;
import javax.xml.stream.*; // StAX API
public class XMLTesterApp {
private static String productsFilename = "products.xml";
public static void main(String[] args) {
System.out.println("Products list:");

[Code] ....

Java Result: 1

BUILD SUCCESSFUL (total time: 0 seconds) mh_sh_highlight_all('java');

On a side note, is it normal if almost everything I writer has to be debugged?

View Replies View Related

Using Data From One Class In Another In Single Java File?

Apr 20, 2015

I am trying to create a second class in a single java file (first time trying this) and want to use data from the first class in the second class but I am not able to do it. What am I missing :

package simplecommissioncalculation;
import java.util.Scanner; // import java.util.Scanner
public class SimpleCommissionCalculation {
public static void main(String[] args) {

[Code] .....

View Replies View Related

Process Data And Determine Winners - Two Dimensional Arrays

Feb 4, 2015

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.

View Replies View Related

JSP :: How To Return List Of Data From Java Class To File

Jan 2, 2015

i'm using eclipse Kepler to create J2EE project.i created student class which return list of information. how to access list in JSP page??

View Replies View Related

Populate ArrayList Of Different Data Types From Text File With Java

Aug 25, 2014

I would like to create an ArrayList from data types stored in a text file.The ArrayList would be multidimensional with two data types; int, String.

Example text file could be:

4 cahiers grand format
3 stylots bic bleu
5 gommes

I find it very difficult for multiple data types i don't see how its possible.

View Replies View Related

How To Improve File Reading Efficiency And Its Data Insertion In Java

Feb 8, 2014

We have an autosys job running in our production on daily basis. It calls a shell script which in turn calls a java servlet. This servlet reads these files and inserts the data into two different tables and then does some processing. Java version is 1.6 & application server is WAS7 and database is oracel-11g.

We get several issues with this process like it takes time, goes out of memory etc etc. Below are the details of the way we have coded this process.

1. When we read the file using BufferedReader, do we really get a lot of strings created in the memory as returned by readLine() method of BufferedReader? These files contain 4-5Lacs of line. All the records are separated by newline character. Is there a better way to read files in java to achieve efficiency? I couldnt find any provided the fact that all the record lines in the file are of variable length.

2. When we insert the data then we are doing a batch process with statement/prepared statement. We are making one batch containing all the records of the file. Does it really matter to break the batch size to have better performance?

3. If the tables has no indexes defined nor any other constraints and all the columns are VARCHAR type, then which operation will be faster:- inserting a new row or updating an existing row based upon some matching condition?

View Replies View Related

Java Servlet :: Read Data From Excel File To Table

Oct 19, 2014

If I want to load data in excel file into table. what is the best way to do it?

View Replies View Related







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