Adding User Input To File - Information Overwritten?
Dec 8, 2014
I need to write a program that will let a user input name, age, email, and cell phone number, and commit the input to a text file. They need to add multiple entries. I figured out how to create the file and write to it, but when the user enters a second set of information, the first is overwritten. How can I make the file be added to instead of overwritten? The following is my code:
try
{
FileWriter writer = new FileWriter("ContactInformation.txt");
BufferedWriter bw = new BufferedWriter(writer);
nameTextField.write(bw);
bw.newLine();
The information is getting stored in the session and i am able to retrieve the same for single user. The trouble starts when 2 user logged in from different browser (for example chrome, IE) from the same machine. The 2nd logged in user, overwrite the session information of first user.
How to prevent this.
My environment: Windows 7 64 bit, IBM websphere server, Oracle 11g, JSP, Sevrlet.
This program contains a superclass and a subclass that will gather the following information from the user:
name, address, phone number, and customer number.
Everything works fine except that I have to create a boolean method in this program that is required to determine based on user input whether they want to be added to a mailing list.
I cannot get this method to work with main, each time it is called it will always return the value but main will constantly read the last statement (else, where it will read "not wanting to be added to the mailing list).
The only way I can get this part of the program to work is by adding an equals method in main that ignores the case, but I am required to write a boolean method so this is not allowed.
Superclass:
public class Person { private String name; private String address; private String phoneNum; public Person(String pName, String add, String number) { name = pName; address = add;
I'm trying to add a tooltip on a cell of a TableView in order to show some information to the user.
This is the code:
colonnaColore.setCellFactory(param -> { TableCell<Appuntamento, Template> cell = new TableCell<Appuntamento, Template>() { @Override protected void updateItem(Template item, boolean empty) { // calling super here is very important - don't
[Code] ....
In few words: there is a cell factory on the cell to show a colored box, then I added a tooltip to the cell. I need informations that are in the item added to the TableView that has type "Appuntamento". So I try to get my element with these code (that in others part of my code works); but here I get a Null Pointer Exception on cell.getTableView() and also on cell.getTableRow().
I'm probably using these methods in a way that was not expected.
I am new to Java an have to Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, and Age. Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns.You should be able to add and remove contacts in the array.
I am new to using arrays. I need to collect user input for book title, author, and # of pages... store that in an array... and then I'm going to need to be able to sort that array. The dialog boxes come up prompting the user for 5 sets of title, author, and # of pages, but when I try to display that information, it isn't working. I am assuming this means that it's not storing the information correctly... so I want to get this corrected before I even try to sort??
import javax.swing.*; import java.util.*; class LibraryBookSort { public static void main(String[] args) { LibraryBook[] someBooks = new LibraryBook[5];
I can insert data in database, delete aslo using JSP. But facing problem while updating the information saved in database as m using MySQL 2008. I want to see the bring saved in database with particular username into the updateinfo.jsp form.
I had to make a program that allowed the user to enter the number of students and the students names and grades and then print out the name with the grade in descending order. right now I only have it where it prints the names out in descending order. how do I get it the print out with the grade?
Here is my code
import java.util.*; public class Grades { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of students: "); int numofstudents = input.nextInt();
I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.
I'm having trouble conceptualizing something. I will post the code, it's works exactly as it should. I create an array and Hash Map to display periodic table of elements information after allowing the user to search by element name or symbol. I want the user to also be able to add elements to the periodic table. I can't really conceptualize how I am going to do that with an array I've already created.
Here's code:
//Create element objects. //Here is where I create my "elements" array, and where I could like to prompt the user to add elements, if desicred. Element[] elements = {new Element("Hydrogen", 1, "H", 1.008,1,1), new Element("Lithium",3, "Li", 6.94,2,1)}; // //Maybe it seems if I prompt the user here to add new element names, symbols, weights, etc, I would be overwriting
I'm attempting to compare user input to a text file that I have set up whenever the user types in an employee ID number. I want to be able to tell the user that either the ID number is valid, or that it is not valid and must be re-entered by comparing it to the employee.txt file, and then record the valid ID number to the timeclock.txt file. I'm recording the next available employee ID number instead of the one I typed in. The output of the program looks like this: i82014/06/06 12:16:56 (I typed 1 as the employee ID.)
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //find selected command String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a properties file and if it exists, pull the key and the value back into a panel
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //find selected command String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a proeprties file and if it exists, pull the key and the value back into a panel ....
I need to write a program where the user inputs name, age, email, and cell and write the user inputs to a text file. I need to have it so the file can be added to if more than one set of information is added. Currently, every time I click the button, the file is overwritten instead of added to. How do I correct this? Current code is as follows:
I'm using the JOptionPane to display and receive information to/from the user. In addition to this, I am using StringBuilder to receive inputs from the user and then manipulate (append) that input to display the desired output.
//Example
(JOptionPane): "Enter text" (user input): Java is cool! (program): *stringBuilder.append(" I love it!") JOptionPane.showMessageDialog( ); .....
Psuedo-like code. The problem is that showMessageDialog(null, string) and not showMessageDialog(string, string). I want to display the enter text: " Java is cool! I love it! " in the JOptionPane. How do I accomplish this, since showMessageDialog only accepts (null, string).
I wanted to write a simple code that receives information from the user (double-digit number and above) and calculates it's numbers.
For instance- The user wrote a number- 234, the software will return the number 9 (2+3+4 = 9).
Tried to use a loop for that, but I got stuck since I didn't know what to write.
This is what I've wrote so far
Java Code:
import java.util.Scanner; public class Calculate { public static void main(String[] args) { System.out.println("Please type a number larger than 9"); Scanner type = new Scanner(System.in); String number1 = type.nextLine();
for( int i = 0; i < number1.length(); i++ ){ int calculate = number1.charAt(i); } } } mh_sh_highlight_all('java');
I'm working a an assignment for my IT/215 class and I'm having a little trouble with my arrays. My code compiles just fine but when it comes to displaying the information I've input into my array it doesn't seem to want to and I'm not sure what I'm doing wrong here. On line 136 originally I had [DVDs [count] = count+1]] but it wouldn't compile. I then put line 136 to [ DVDs[count] = new Inventory();] and I think that's were my issue is but I'm not sure....
// Purpose:the purpose of this software is to display inputs as wells as the stocks and price of inputs.
class Inventory { private double ItemNumber; //to store Item number private String ItemName; //to store Item name private double UnitsInStock; //to store number of units in stock private double UnitPrice; //to store Unit price private double InventoryValue; //to store Inventory value private double TotalInventory; //to store Total Inventory value
I am attempting to make a heart rate calculator program. Here is a little overview of what I am trying to do. It must use a constructor and get and set methods. It must print heart rate ranges and the user's information(age).
// Use scanner to get inputs import java.util.Scanner;
// Declare class public class HeartRates { private int Age; private int DayOfBirth; private int MonthOfBirth; private int YearOfBirth; private double MaxHeartRate; private double MinTargetHeartRate;
I'm making a program for school that reads a text file with answers to a personality test and prints the temperament to an output file. Problem is, it sets the temperament for the first person to INFJ and then prints INFJ for the rest of the people too. My code is below, and the input file 'personality.txt' goes like this:
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 been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".