this is an example of the file:

Caldwell E.,CSC,25,5,500.00,250.00,100.00,20.00,1000.00

there are 18 of these entries in the file consists of : last name and first initial,department,miles walked,number of pledges, and the pledge amounts.

I have to :

1. display the file content
2.compute the total pledges obtained by each person
3.display a list of names and there total pledge amounts sorted by total pledge amount.
4.display the following by department
a. Total participants
b.total amount of pledges in $

this is the code i have so far:

/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
*
*/
public class FileInput
{



public static void main(String[] args) throws IOException
{
File file = new File("README.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
System.out.println(dis.readLine());
}
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


}
}

someone please help me if you can!!!!!!!

Recommended Answers

All 2 Replies

ok obviously im not gonna do this all for you, but the best way of doing this is creating an object for each person which would contain all there details 'name, pledge etc' then you could do anything you please with the data. Or you could alternatively load all this data into an array by splitting the text file at every ",". Like so

while (dis.available() != 0) {
String data = dis.readLine();
String[] record = data.split(",");

System.out.println(record[2]);
System.out.println(record[3]);

// this  would print 25 then 5

      }

now you could do this for each record you have and store them in a multidimensional array (which isnt really true for java as it stores arrays of arrays)

but for you to understand this i suggest looking here http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

its best to try and grasp the code ive shown above first and progress from there as you will inevitably have more loops. Post back with more questions if you have any.

commented: Good advice for beginners. +18

1. get the comma separated data file read into an array as fungus suggested then process it.
2. get the values put inbetween "", then import it into excel. You will have the calculations done very fast. The process may appear to be lengthy, but is not. Use the find Find Replace mechanism in any text processor such as Edit or Notepad and replace all , with ",", most of the work would be done except for the first ans last entries, do those manually
3. If your program is generating this data, get it to generate them with double quotes

hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.