-
July 28th, 2012, 08:28 AM
#1
Write a Java program that reads file
Write a Java program that reads the file "X", and prints to the console the file update time, the list of marks for a given UB number and the corresponding “marks gained” value.
So far I have got this and not im totally stuck :/
Help!
Code:
package textcopy;
import java.io.*;
/**
* This class demonstrates the number of students matching the UB number criterion and the average mark.
*
* @author MSheraz3
*/
public class TextCopy {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
BufferedWriter writer = new BufferedWriter(new FileWriter(args[1]));
String line = null;
while ((line=reader.readLine()) != null)
if ( line.split(",")[0].matches("\\d*7\\d*") )
{ writer.write(line); writer.newLine(); }
reader.close(); writer.close();
double sum=0; int counter=0;
{ sum = sum+Integer.parseInt(line.substring(9)); counter = counter+1; }
System.out.println("Students: "+counter+"\nAverage mark: "+sum/counter);
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|