Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. You are given a text file containing roster of a class in the format Bannerid

ID: 3774211 • Letter: 1

Question

1. You are given a text file containing roster of a class in the format

Bannerid/ Name/ Score

+34343431 / Sam / 90

Write a program that will read the text file and store the following in the following output file.

1. If there is any duplicate bannerid, it will store only once.

2. Check the bannerid has 9 characters, if no, then add X before the bannerid for the record in the output file.

3. Compute the maximum and average of the score and output in the output file.

Use methods and make the code modular.

Test the program on an input file with 5 records. Upload your input file and java source code. The format of the output file

Bannerid Name Score

+34343431 XYZ 90

+83948394 ACB 40

**********************************

Maximum is 90

Average is 65.

DR JAVA Format please :))

Explanation / Answer

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.OutputStreamWriter;

import java.io.Writer;

import java.util.HashSet;

public class BannerID {

   public static void main(String[] args) {

       // Scanner in = new Scanner(System.in).useDelimiter(" ");

       // System.out.println("Please enter filename with full path");

       // String filename = in.next();

       String filename = "/Users/Akhilaperumalla/Desktop/readme.txt";

       try {

           BufferedReader reader = new BufferedReader(new FileReader(filename));

           String line;

           Writer writer = null;

           HashSet<String> hm = new HashSet<String>();

           writer = new BufferedWriter(

                   new OutputStreamWriter(new FileOutputStream("/Users/Akhilaperumalla/Desktop/output.txt"), "utf-8"));

          

           writer.write("Bannerid Name Score ");

           int count = 0,max=0,sum=0;

           while ((line = reader.readLine()) != null) {

               // System.out.println(line);

               if (count != 0) {

                   String t[] = line.split("/");

                   if(!hm.contains(t[0]))

                   {

                       hm.add(t[0]);

                       int marks=Integer.parseInt(t[2].trim());

                       sum+=marks;

                       if(marks >max)

                           max=marks;

                       if(t[0].length() !=9)

                           writer.write("X"+t[0]+" "+t[1]+" t[2]");

                   }

               }

               count++;

           }

           System.out.println("Maximum is "+max);

           System.out.println("Average is "+sum/hm.size());

          

           reader.close();

           writer.close();

       } catch (Exception e) {

           System.err.format("Exception occurred trying to read '%s'.", filename);

           e.printStackTrace();

       }

   }

}

Input file

Bannerid/ Name/ Score
+34343431 / Sam / 90
+5343431 / Ram / 60
+34343431 / Sam / 90
+34343431 / Sam / 90
+34343431 / Sam / 90

output file

Bannerid Name Score
+34343431 Sam 90
X+5343431 Ram 60