GUI Application - Read Some Person Details From A File And Then Put The Result In JList
Aug 31, 2014
I'm new to programming and java and I'm trying to understand how exactly this piece of code works and what exactly does. I'm trying to make my first GUI application and to read some person details from a file and then put the result in a Jlist.
private static final String SEPARATOR = ",";
public static ArrayList<Speaker> getAllMembers() {
ArrayList<Member> members = new ArrayList<Member>();
try {
File file = new File(Resources.MEMBERS_TXT);
Scanner fileReader = new Scanner(file, "utf-8");
String[] properties;
Create a Java application that prompts the user to enter their personal details: First name, last name, gender, address, suburb, postcode, and phone number. Then the program displays all of your personal details to the screen as illustrated. Name the file PersonDetails.jav
package exe import java.util.*; public class Review2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your full name: "); String name = scanner.next();
[Code]...
If you cant tell straight away how i have stuffed up, what is happening is this;
When i am promoted to enter my name, 'John Smith'. The word 'John' would be stored in the name variable, while 'Smith' is stored under gender, so the next prompt is then 'Whats your address?'
So its only assigning one word per variable, now as far i understand, a string should not work that way. So where is my mistake?
i am trying to do a program captures keystroke and mouseclick from user in a textarea and insert the details intoa text file using java. Mainly such as delay between keys, no. of times backspace being pressed, alt tab press and copy paste mouse click.
The program should copy person with the highest percent from the file 'plik1', and then put it to the file 'plik2'.The problem occurs while compiling.
Java Code: string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type string cannot be resolved to a type mh_sh_highlight_all('java'); Code:
I have printed the result of my program into an output file.
For some reason I can't figure out how to get the file output.txt to actually print.
I've tried printing it like I would normally print a file but it's not working.
Java Code:
final PrintStream console = System.out; File file = new File("output.txt"); PrintStream out = new PrintStream(new FileOutputStream(file)); System.setOut(out); System.out.println(collection.toString()); System.setOut(console);
What do I do after this? mh_sh_highlight_all('java');
It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?
My question now is how to increase the size of buffer in order to read a larger InputStream ? BufferedInputStream() default size is private static int defaultCharBufferSize = 8192; private static int defaultExpectedLineLength = 80;
How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not work!
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.....
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 have this Contact List program and im stuck on how to make my contact list show their different details. I don't know what to do , I want my program to be like this. What should I do next to make my every entry have different information then show on to the right side of the panel the information when i click the show details button .
Well my code is supposed to ask for an input file and then (ex: input.txt), read the input file and create an output.txt file with the anagram for the words in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file!
/* This program will read a file given by the user, read the words within the file and determine anagrams of the given words. If the file that the user inputs is empty, then the program will output "The input file is empty." * The program will read the file line by line, counting the total number of words read. If there are more than 50 words, "There are more than 50 words." * will be printed, and the program will terminate. After each line is read, the words in the line will be separated,punctuation characters will be removed, and upper case characters will be switched to lower case. * If any word is larger than 12 characters, that word will not be considered in the total amount of words in the file and it will not be sorted. * After each word is read, the letters will be sorted and stored into an array containing each * word's 'signature'. After all the words have been read, words will be printed to the output file on the same line based upon their signature. */
public class Anagram { //Creating constants for maximum words in file and maximum chars in word public static final int MAX_CHARS = 12; public static final int MAX_WORDS = 50;
I am trying to create a file browse option in my jsp and later after browsing, all i want to do is to read that file in my jsp without saving it into that database so that i can perform encryption for it and save that encrypted file later into my database. please provide reference link so that i can refer to some applications and and move ahead with my work.
I have one jsp page in which I have listed some service records fetched from Database. I have made one of the column, for eg. Service ID to be link, which should display all the details of that service when clicked. I want those details to be displayed in lightbox. I tried doing it but when any service ID link is clicked, it displays same(First Service in record) service details.How do I pass reference of that current service to lighbox effect.
I am trying to write to a file but everything I have tried doesn't seem to work. What I want to do is read a file and then output back to the same file on a new line. The text file contains the sentence "Java is a programming language".
import java.util.Scanner; import java.io.*; class HW1B { public static void main(String[] args) { Scanner fileIn = null; try { fileIn = new Scanner (new FileInputStream("text.txt"));
[Code] ....
These are the errors :
HW1B.java:19: error: no suitable constructor found for Scanner(FileOutputStream) fileOut = new Scanner (new FileOutputStream("text.txt")); ^ constructor Scanner.Scanner(Readable) is not applicable (argument mismatch; FileOutputStream cannot be converted to Readable) constructor Scanner.Scanner(InputStream) is not applicable
[Code] ....
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 2 errors
I am trying to read a file and input each line of the file into an array. I have not set the array size as I was hoping to fill the array using a while loop. Unfortunately the scope of the array does to work inside the while loop so I am being told that the array 'students' has not been initialised even though it has just outside of the while loop. Is it possible to do what I am trying to without having the array initialised in the while loop as surely the array will be reset every time if it was in the while loop? Here is my code:
public static void students(String file) throws FileNotFoundException { try { File studentInfo = new File(file); Scanner input = new Scanner(studentInfo); String[] students;
When I run my program and choose option 2 to get contact details I am expecting it to display as follows (First Name, Last Name): Contacts how have been entered:
0) John Doe 1) George Smith 2) Nancy Davis
Please enter the number corresponding to the contact you would like to view:
Instead for a personal contact it is displaying as follows:Contacts who have been entered:
0) Doe 1 F St. (last name, address)
Please enter the number corresponding to the contact you would like to view:
Instead for a business contact it is displaying as follows:Contacts who have been entered:
0) 1 F St. jd@gmail.com (address, email)
Please enter the number corresponding to the contact you would like to view:
Then when I enter the number to display the contact for personal it is returning me only first name and business is only returning me first and last name. It should be returning the full contact info that was put in during the add contact step. I thought I programmed everything properly but it isn't displaying what I want to seeMy code is listed below.
ContactList
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package contactlist; import java.util.ArrayList; import java.util.Scanner;
I want to display product details such as product image, name, price in a one cell of a table tag on jsp page. There should be multiple rows and 3 cells per row in the required output.i have written the following code:
This code displays all cells in only one row. I used colspan but its not working...I have attached the snapshot of above code output and required output
public class Person implements Comparable<Person> { // the age of the person private int age; //the name of the person private String name; //the Integer object to wrap the age value; private Integer ageWrap;
[Code] .....
The collection library has a class named TreeSet, which is an example of a sorted set. Elements in this set are kept in order. Carefully read the description of this class, and then write a class Person that can be inserted into a TreeSet, which will then sort the Person objects by age.
This is the exercise I am trying to solve. And this is as far as I have gotten to. Is it possible to sort my setOfPersons TreeSet directly? I tried to use
Collections.sort(setOfPersons)
method but it wont compile, and I realized that it is not applicable to TreeSet. So I made the
sortByAge()
method to do it indirectly...
I am puzzled though because in the exercise it states
write a class Person that can be inserted into a TreeSet, which will then sort the Person objects by age.
meaning that the TreeSet will sort the Person Objects and not my class..
I'm supposed to calculate and display the number of total days, and then the number of months, and days from now (when the program is run) to when the person's next birthday is (no leap year). Here is my code:
import java.util.Scanner; import java.text.*; import java.lang.System; import java.util.Date; import java.util.Calendar; public class CSCD210Lab3 { public static void main (String [] args)
[Code] .....
When I call daysFromMillis in the print statement, if I enter in a birthday of 02/17/1993, I will get an answer of "our birthday is 5435 days from now."
User-defined classes. The concept of getters and setters goes right over my head. Right now we're to write a program to test the Person class below. We have to create 2 instances of the class to test each constructor, and test each method.
class Person { // Data Members private String name; // The name of this person private int age; // The age of this person private char gender; // The gender of this person // Default constructor public Person() { this("Not Given", 0, 'U');
[code]....
then my output will print out the name. But the assignment doesn't tell us to modify the Person class at all, just to create a tester one.
I am writing a program that needs to read from a file, but I can't even get it to open. I have tried saving the .txt file 2 different ways. First, I saved the file to my src/package folder. Then I tried just the src folder. Then I tried going through Import/general/filesystem/ and selecting the root directory. However, my program is still unable to open the file.
How to write a program that will verify the correctness of a person`s birth date in java. The birth date is to be typed in by the user. the program should verify the following: Birth date entered should be of type java.util.Date(), Birth date may not be in future, Age may not exceed 110 years.
I have to write a program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calaculated with the following formula:
BMI = Weight X 703/Height^2
where weight is measured in pounds and height is measured in inches. The program should display a message indicating whether the person has optimal weight, is underweight, or is overweight. A sedentary person's weight is considered optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered underweight. If the BMI value is greater than 25, the person is considered overweight.However I can't seem to get rid of these errors:
----jGRASP exec: javac BMI.java BMI.java:28: error: cannot find symbol Scanner keyboard = new Scanner(System.in); ^ symbol: class Scanner location: class BMI BMI.java:28: error: cannot find symbol
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 am trying to read from a file and storing them back in the file but its not working, I think the way I am reading is wrong or something. Is the for loop correct way ?
try { in = new BufferedReader(new FileReader("Events_data.txt")); for (int x = 0; x <= Events.length; x++) { tid = in.read(); te = in.readLine();