lolipop12

OS Lab 1.4

Mar 21st, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9.  
  10. public class HW01_4 {
  11.     public static void main(String[] args) throws IOException {
  12.        
  13.         BufferedReader br;
  14.        
  15.         try {
  16.             br = new BufferedReader(new InputStreamReader(new FileInputStream("rezultati.csv")));
  17.         } catch (FileNotFoundException e) {
  18.             System.out.println("Ne e pronajden takov fajl!");
  19.             return;
  20.         }
  21.        
  22.         BufferedWriter bw;
  23.        
  24.         try {
  25.             bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("rezultati.tsv")));
  26.         } catch (FileNotFoundException e) {
  27.             System.out.println("Ne e mozno da se otvori toj fajl!");
  28.             return;
  29.         }
  30.        
  31.        
  32.         String novRed = br.readLine();
  33.         String oceni[] = novRed.split(",");
  34.         int brOceni = oceni.length-1;
  35.         int zbirOceni[] = new int[novRed.length()];
  36.         int vkStudenti = 0;
  37.        
  38.         bw.write(novRed.replace(",", "\t")+"\n");
  39.        
  40.         while ((novRed = br.readLine()) != null){
  41.             String oceniUcenik[] = novRed.split(",");
  42.             int zbir = 0;
  43.             vkStudenti++;
  44.            
  45.             for (int i=1; i<oceniUcenik.length; i++){
  46.                 zbir += Integer.parseInt(oceniUcenik[i]);
  47.                 zbirOceni[i] += Integer.parseInt(oceniUcenik[i]);
  48.             }
  49.                
  50.             System.out.println("Studentot: "+oceniUcenik[0]+" ima prosek: "+(zbir*1.0/brOceni));
  51.        
  52.             bw.write(novRed.replace(",", "\t")+"\n");
  53.         }
  54.        
  55.         for (int i=1; i<oceni.length; i++)
  56.             System.out.println("Po predmetot: "+oceni[i]+" prosecnata ocena e: "+(zbirOceni[i]*1.0/vkStudenti));
  57.        
  58.         br.close();
  59.         bw.flush();
  60.         bw.close();
  61.     }
  62. }
Add Comment
Please, Sign In to add comment