daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Oct 22nd, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. class Interval {
  4.     private int minInt, maxInt;
  5.     private int nrTestate=0, nrTestateInt=0;
  6.     public double percentage;
  7.    
  8.     public Interval(int min, int max) {
  9.         this.minInt = min;
  10.         this.maxInt = max;
  11.     }
  12.    
  13.     public void isInInt(Double x) {
  14.         this.nrTestate++;
  15.         if(x>= minInt && x<= maxInt)
  16.             this.nrTestateInt++;
  17.         this.percentage = (double)this.nrTestateInt / (double)this.nrTestate * 100;
  18.     }
  19.    
  20.     public String toString() {
  21.         return "["+minInt + " ; " + maxInt + "] percentage = " + percentage+"%";
  22.     }
  23. }
  24.  
  25. class Client {
  26.     public static void main(String argv[]){
  27.         try{
  28.         BufferedReader file_char_stream = new BufferedReader(new InputStreamReader(new FileInputStream("interval.dat")));
  29.         PrintStream outputFile;
  30.  
  31.         if(argv.length==1)
  32.             outputFile = new PrintStream(new FileOutputStream(argv[0]));
  33.         else
  34.             outputFile = System.out;
  35.        
  36.         Interval i1;
  37.         Integer min = new Integer(0);
  38.         Integer max = new Integer(0);
  39.         String inputFile;
  40.        
  41.         String line = null;
  42.         while((line = file_char_stream.readLine())!= null) {
  43.             min = min.parseInt(line);
  44.             line = file_char_stream.readLine();
  45.             max = max.parseInt(line);
  46.             line = file_char_stream.readLine();
  47.             inputFile = new String(line);
  48.            
  49.             i1 = new Interval(min, max);
  50.            
  51.             BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
  52.            
  53.             while((line = input.readLine())!= null) {
  54.                 Double x = new Double(0);
  55.                 x = x.parseDouble(line);
  56.                 i1.isInInt(x);
  57.             }
  58.            
  59.             outputFile.println(i1.toString());
  60.             //System.out.println(i1.toString());
  61.            
  62.         }
  63.         outputFile.close();
  64.         file_char_stream.close();
  65.         //input.close();
  66.         } catch(IOException e) {
  67.             System.out.println("Eroare la operatiile de intrare-iesire!");
  68.             System.exit(1);
  69.         }
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top