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


Reply With Quote

Bookmarks