Sorting Data Alphabetically By Second Name In A File?

Apr 11, 2013

I have a problem sorting this file alphabetically by second name. Basically, my method sorts each column alphabetically but i would like to sort the file according to the second name.

File:
Moe     Carl
Saul     Sergio
Rocky     Louis
Ike     Ziken     

This is how my method sorts the file:

Ike          Carl
Moe          Louis
Rocky          Sergio
Saul          ziken
     
Instead
Moe     Carl
Rocky      Louis
Saul     Sergio
Ike     Ziken

Code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
class thedata implements Comparable
     {               
          private String firstname;
          private String secondname;

[Code] .....

View Replies


ADVERTISEMENT

Sorting A Text File Alphabetically

Oct 13, 2014

So we have to create a code that reads in a file that has a huge list of words. Our code has to convert every word to all lower cases and then re-sort alphabetically. I was able to turn everything to lower case, but for the re-sorting I keep getting a null pointer exception on the line of the if statement.

import java.io.*;
public class readDict {
public static void main(String args[]) {
try {
System.out.println("Opening the file...");

[Code] ....

View Replies View Related

Sorting A Map Alphabetically

Nov 30, 2014

I'm trying to create a method that takes a map and sorts it alphabetically. I think I have the logic correct but I'm getting errors when I run it:

private static void sortMapAlphabetically(
Map<String, String> termsAndDefinitions) {
Map<String, String> tempMap = new Map2<String, String>();

[Code].....

View Replies View Related

Program To Accept 10 Name In String And Sorting In Bubble Sort Alphabetically

Jun 10, 2014

import java.io.*;
Class bubble
{
public static void main()throws IOException
{
BuffetedReader br=new BufferedReader (new InputStreamReader (System.in));
int j, k, temp;
String st[]=new string [10];

[Code] .....

View Replies View Related

Sorting CSV Data Into Rows That Contains Duplicates In Columns

Apr 30, 2015

How to sort data from a .csv file. The file has a column that contains duplicate groups, and a column that has duplicate employee id's. I need to take the data and sort it into rows. The employee's id will be in the first column, then the groups the employees belong in will occupy the following columns. The groups and employees are dynamic.

groups| empId
-----------------
Group A| a1234 |
Group A| e3456 |
Group A| w3452 |
Group A| d3456 |
Group A| j7689 |
[Code] ....

I want to format the .csv as follows:

--------------------------
empId | group 1 | group 2 |
--------------------------
a1234 | group A | group B |
---------------------------
w3452 | group A | group B |
---------------------------

View Replies View Related

Reading / Sorting And Writing A File

Dec 4, 2014

I need to read lastname, firstname, and ssn from a text file and sort them based on oneof those three creiteria. Here is my person class:

public class Person implements Comparable {
private String lastName, firstName, ssn;
private static int sortBy = 1;
public static final int LASTNAME=1, FIRSTNAME=2, SSN=3;
public void setSortMethod(int method) {
if(method != LASTNAME && method != FIRSTNAME && method != SSN) {
throw new IllegalArgumentException();
} else {

[code]....

how to sort my info and store it into an array and then write that info into my new file.

View Replies View Related

Swing/AWT/SWT :: Sorting In File Tree Node

May 12, 2014

I have requirement of sorting the files in tree structure with name and timestamp of creation, i am new to swings...

Here we are using FileTreeModel.

Root Folder:
folder1;
file1
file2
.
.

View Replies View Related

Sorting A Text File With Strings And Numbers

Oct 16, 2014

how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:

blue 18
blue 10
red 27
yellow 4

public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;

[code]....

I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers

View Replies View Related

Reading A File / Sorting It And Displaying Its Content On Screen

Jan 19, 2014

I have a program that writes a user's input to a file.

The input consists of several loops. In each loop the user enters a student number, the student first name and last name and then several exam results. Each student has different number of exams, depend on the user input.

For instance, the input can be (explanations are in brackets but not in the actual file):

505 (student number)
efron (last name)
ben (first name)
3 (no. of exams)
88 (1st exam mark)
70 (2nd exam mark)

... and so on

I need to write a program that reads that file and writes it to the screen, but it needs to do it in ascending order according to the student number.

Leaving aside the format it will be displayed on the screen, my question is how should I sort the data by the student number?

I though about first reading each student as an array, but my problem is that each array contains different number of elements (depends on the number of exams) and also each array containד both strings (first and last names) and ints.

View Replies View Related

Cycle Through Database Entries Alphabetically

Aug 6, 2014

I have a database of peoples names linked up to a from to enter a new employee.The form has a previous and next button that should cycle through the employees alphabetically.What im doing the cycle by now is ID which isnt in alphabetical order and just goes by the order they where entered in.

Is there any way to cycle through alphabetically instead? Is running a query each time the next/previous button is pressed the correct way or should it just grab all the names in the array. Theres probably 150 names.

View Replies View Related

Servlets :: How Does Multipart / Form-data Send Data Over Network During File Upload

Apr 9, 2015

I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?

View Replies View Related

User Input All Of Data On A Single Line And Implement StringTokenizer To Assign That Data To File

Mar 21, 2015

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();

[Code] ....

View Replies View Related

When Deleting Data From File / Temp File Won't Rename Back To Original File

Apr 23, 2015

I am trying to remove a line based on user input. myFile.txt looks like:

Matt
Brian
John

However when I enter "Brian" (to remove this line), It is deleted on the temp file (myTempFile.txt), but not renamed back to the original file (myFile).

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
 
[code]....

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

Taking Range Of Names In Array And Outputting Them Alphabetically - OutOfBoundsException

Apr 24, 2014

At the moment I am studying it and the problem is Taking a range of names in an array and outputting them alphabetically, But for some reason I get an outOfBoundsException. And its starting to get to me. How to put the code in

import java.util.Scanner;
import java.util.Arrays;

public class lab241 {
public static void main(String[] args) {
Scanner kb= new Scanner(System.in);
String[ ] names = new String[4];

names[0]= ("Horatio");
names[1]= ("Anatoly");
names[3]= ("Evelyn");
names[4]= ("Anna");
Arrays.sort(names);
for(String N: names){

System.out.println(N);

View Replies View Related

Sort User Input 3 Words Alphabetically And Output Middle Word

Feb 8, 2014

I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically.

import java.util.Scanner; //The Scanner is in the java.util package.
public class MiddleString {
public static void main(String [] args){
Scanner input = new Scanner(System.in); //Create a Scanner object.
String str1, str2, str3;
System.out.println("Please enter three word words : "); //Prompt user to enter the three words

[Code]...

we havnt done arrays yet and I THINK i have to do compareTo.....how to use it?

View Replies View Related

Sort String List Alphabetically With CompareTo Method / If Else Statements - Logic Errors

Oct 6, 2014

I'm having trouble with sorting Strings- 3 strings inputted by user, and I would like to output them in alphabetical order. I've used the str.compareToIgnoreCase method, and then I've tried to loop them through a series of if/ else statements. Everything I've been able to find online (including the forums here) has suggested to use the Comparator class, or to put the strings into an array, and sort list- I really would like to stick with just the String class, and its methods .

The program itself works and compiles, but I am getting logic errors that I have been unable to solve. I'm using IntelliJ Idea, and I've ran it through the built in debugger, about 100+ times (not exaggerating, lol) just to see what it's doing in particular scenarios. For instance, I can get c, a, b, to print out as a,b,c correctly, but a,b,c, will print out as b,a,c.

For me this is kind of like a Sudoku puzzle, or a Rubik's cube! Each time I fix one scenario, it breaks another one, so I don't know if there's a(logic) solution to fix all possible scenarios (abc, acb, bac etc... to all print abc) or if possibly I just need more if statements. I've only pasted in the area where I'm having problems (the if statements). I'm a big fan of the "Next Line" syntax.

(Note: please assume the non relevant content- import Scanner class, main method, etc... I didn't want to paste the entire program.)

System.out.println("Enter the first statement: ");
//input.nextLine();
string1 = input.nextLine();
System.out.println("Enter the second statement: ");
string2 = input.nextLine();
System.out.println("Enter the third statement: ");
string3 = input.nextLine();

[Code] ....

View Replies View Related

Read Text File Into Array Ask User To Save File And Print Data

Jul 14, 2014

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.

[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

[Code]....

View Replies View Related

Executable Jar File - Will Not Load Data From CSV File

May 5, 2015

I have a small application that I have been working on for several months. It works great. Now when I created an executable .jar file for it, it will not load data from a .csv file. I have tried looking into everything I can think if. I checked file paths, etc. I am using OpenCVS to read the csv. Is there an issue with that when you include it into another .jar file? I am trying to log if there is an error but I don't even get an error. I just doesn't run past that statement...

View Replies View Related

Copying Data From One File To Another

Dec 27, 2014

[code=java]
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
FileReader fr = new FileReader("gautam.txt");
BufferedReader br = new BufferedReader(fr);

[Code] ....

Whats wrong with this code?

View Replies View Related

Saving Data To A File

Oct 1, 2014

I am learning FileIO and I am having an ArrayIndexOutOfBoundsException for the following code and I am unsure why...

import java.io.*;
public class ArrayWriter {
public static void main(String[] args) {
PrintWriter fout = null;
int[] data = new int[10];
for(int i = 0; i<data.length; i++) {
data[i] = (int)(Math.random() * 101);

[Code] ....

View Replies View Related

Saving Data To TXT File

Oct 27, 2014

I was able to create the txt file. How to get it to output my code. I know it's an object and it is a way to save data.
 
package multiplicationFile;
import java.util.Scanner;
import java.io.*;
public class Multiplication {
public static void main(String args[]) throws IOException {
PrintWriter outF = new PrintWriter("multiplications.txt");

[Code] ....

View Replies View Related

Data Validation Of XML File

Mar 23, 2015

I have an xml file whose data needs to be validated with 250+ rules, the size of the xml can range from 4MB to 50 MB. Have the following questions.
 
1. Where the Rules should be defined, as i would like them to dynamically controlled(instead of hard coding)
2.  Given the size of the data and input being xml, how should i approach this problem(considering the rules might change etc)
3.The names of the UI and XML tag names will be different, so when should the translation takes place
 
Following is the structure of the xml :

<DATA>
<Parent>
     <Fields>
     //All the data like name, age, height, weight, blood group etc goes here
     </Fields>
     <Childs>
     <Name = 'Andrew' id = 7560>

[Code] ....

View Replies View Related

Writing A Sequential Data File?

Dec 15, 2014

I need to write a program that, when a button is pressed, will add the user input to a table AND write it to a sequential data file. I have everything done accept for how to write the data sequentially(all input data on the same line in the file). The following is part of the code:
 
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
dtm.addRow(new Object[]{donorName.getText(),charityName.getText(),donationAmmount.getText()});
//Adds user input to the table 
try
{
FileWriter writer = new FileWriter("FundraisingInformation.txt",true);//Creates file or adds to it
  BufferedWriter bw = new BufferedWriter(writer);

[code].....

I would need the file output to be in the following format:

donorName charityName donationAmmount

As I said, using the .write(bw) i know how to make it look like:

donorName
charityName
donationAmmount

View Replies View Related

Saving Data To A File That Has Been Entered

Jan 21, 2014

I am trying to save the data a person enters to a file. See code below. It is compiling however the file created only shows largest =89, i want the file to show all the data a person enters.

import java.util.*;
import java.io.*;
public class LargerOfThree3{
public static void main(String args[]){
Scanner in = new Scanner(System.in);

[Code] ...

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







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