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) {
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records { public static void main(String [] args) throws IOException { Scanner input = new Scanner(System.in); FileWriter fw = new FileWriter("dbs3.java"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw); System.out.println("NEW EMPLOYEE DATA SHEET"); System.out.print("Number of new employees: "); int number = input.nextInt();
I have to read data from a text file and print it in a new text file. An example of one line is like this: Johnson 85 98 75 89 82
I then have to take the average of all the numbers and assign a "grade" to the numbers for each line of the text file and make a new file so it looks like this for 10 lines:
Name 1 2 3 4 5 Average Grade
Johnson 85 98 75 89 82 85.80 B
My problem is extracting the data from the file so I can use it.
I have created an application using hibernate and struts.In which a form is created where the user will enter all its personal details(for e.g name ,phone no. and address).
Here for address I have used textarea and whenever user enters the address, sometimes it can be a long string also.
So the problem is if a long string is entered then while displaying that ,address comes on single line and the page is stretched.
how to break this single string into mutiple lines in java class?
How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.
public class A(){ void print(){} } class B{ void function_B(){} } class C{ void function_C(){} }
Here, A, B, C are in the same package. But class D is in different package.
I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow
public class Stack{ public boolean isEmpty(){}; public void push(int n){}; public int peek(){}; public int pop(){}; }
I'm trying to share an hashmap(or any other stuff to share data) between a java class and a servlet. The hashmap has to be filled into the servlet with some data and then I have to get those data from the java class.
What is the best approach? I cannot use a DTO because I have several concurrent requests to my servlet.
I want to have two threads running in my class, one will be downloading info from a website then putting the thread to sleep for a little bit, then repeating. The other will be sending information to a website then putting the thread to sleep for a little bit, then repeating. Is it possible to do this in my main class? I already have one thread using run() for downloading the info and sleeping can i make another?
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;
"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.
I've been into java for about 4 months now, No complaints so far, it's pretty awesome! So I understand Polymophism pretty good, I did some Animal classes and it worked out neatly.
However. I just can't seem to find my way in OOP when trying to implement in on a Calculator Class I wrote. As you mind know, a calculator can be separated into many classes. But I actually just want it to be separated into some OO like: | Calculator | CalcGUI | CalculatorFunctions | CalcRun.
I tried separating the single Calculator class, however, my calculator Buttons didn't work after that, anymore..
**Getting data on from rfid scanner as Serial rs232 port in JFrame**, in this case I have made a JFrame form and I have a JTextField for storing data rfid as a String. Actually, I found a class from internet that read the RFID reader as byte, now How To get data from my RFID Class to my JTextfield Jframe in my main class as String?
I have a string of variable tags (tag) filled with variables, and using a Scanner (scan) to manipulate and generate data dictionary add cards for each. The variables are delimited with new line character, and the variables are structured such that the actual name of the variable contains info as to its data type, size, etc. What I need to do is move the scanner to a particular point into the string then use .nextInt() or similar. I don't want to do this to the whole variable, just where I start it from. How can I do this?
Scanner scan = new Scanner( tag ); int ptr = tag.indexOf( "_" ); ptr++; if ( Character.toLowerCase( tag.charAt( ptr ) ) == 's' ) // then start at the "_" character and grab the nextInt()
I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."
It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.
When I click on "Clean and Build" NetBeans generates a .jar file and inside the folder "dist" it add a directory called "lib" with all the java libraries used to implement the program. I would like to achieve with this IDE an unique .jar file that includes everything you need such as Eclipse does by default. Is it possible?
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:");
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:
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?
I'm learning jQuery to integrate into a JSF application but finding some confusion on the correct syntax especially when it comes to combining double and single quotes in the jQuery scripts. So for this particular page I want jQuery to traverse through a list of documents and put icons next to each document to state what type of document each is (ie: PDF, doc, xls). I can get this to work using normal html markup but I get a Syntax Error - Unexpected Token exception in the browser.
I'm confused about whether this means I need to use the right html references for the JSF element I wish to traverse or whether this is a problem with the way I'm using my quotes.
Also I'm not sure how to correctly reference jsf tags inside jQuery scripts. So for an ordinary html page I execute the following jQuery script:
I need to write out multiple BufferedImages to a single tiff file. Each image represents a seismic time slice which can be several megabytes in size. I have used the TIFFEncodeParam.setExtraImages method and saved all my BufferedImages to a vector but my since I create so many BIs I keep running out of memory. Is there a way to create a BI, write it out to a TIFF file, then discard the BI and create the next one?