Advertisement
NB52053

JAVA_FINAL 1

Aug 3rd, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package mid2;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.PrintWriter;
  11.  
  12. public class Olympic1 {
  13.     public int sum1,sum2,sum3 ;
  14.     public int [] a = new int [5];
  15.    
  16.      BufferedReader bufferedReader = null;      
  17.      String line = "";
  18.     public void read(){
  19.        
  20.         try{
  21.            
  22.          
  23.             bufferedReader = new BufferedReader(new FileReader("C:\\Users\\common.LAB8PC-03\\Documents\\NetBeansProjects\\Mid2\\olympic.txt"));
  24.    
  25.             int i = 0;
  26.             while((line = bufferedReader.readLine()) != null){
  27.                
  28.                 String [] s = line.split(" ");
  29.              
  30.                 System.out.println(s[0]+"\t"+s[1]+"\t"+s[2]+"\t"+s[3]);
  31.                
  32.                 int gold = Integer.parseInt(s[1]);
  33.                 int silver = Integer.parseInt(s[2]);
  34.                 int bronze = Integer.parseInt(s[3]);
  35.                
  36.                 int sum = gold + silver + bronze  ;
  37.                
  38.                 System.out.println("Sum of medals: "+sum+"\n");
  39.                
  40.                 a[i] = sum;
  41.                 i++;  
  42.                
  43.              
  44.             }  
  45.            
  46.         }
  47.        
  48.         catch(Exception e){
  49.             e.printStackTrace();
  50.         }
  51.     }
  52.    
  53.    public void write(){
  54.         try{
  55.         PrintWriter pw = new PrintWriter("processed.txt","UTF-8");
  56.         for(int i = 0; i<5;i++){
  57.            
  58.         pw.println("Summaion of medals: "+a[i]);
  59.         }
  60.         pw.close();
  61.         }
  62.         catch(Exception e){
  63.             e.printStackTrace();
  64.         }
  65.     }
  66.    
  67.     public static void main(String [] args){
  68.         Olympic1 olympic = new Olympic1();
  69.         olympic.read();
  70.         olympic.write();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement