Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Interval {
- private int minInt, maxInt;
- private int nrTestate=0, nrTestateInt=0;
- public double percentage;
- public Interval(int min, int max) {
- this.minInt = min;
- this.maxInt = max;
- }
- public void isInInt(Double x) {
- this.nrTestate++;
- if(x>= minInt && x<= maxInt)
- this.nrTestateInt++;
- this.percentage = (double)this.nrTestateInt / (double)this.nrTestate * 100;
- }
- public String toString() {
- return "["+minInt + " ; " + maxInt + "] percentage = " + percentage+"%";
- }
- }
- class Client {
- public static void main(String argv[]){
- try{
- BufferedReader file_char_stream = new BufferedReader(new InputStreamReader(new FileInputStream("interval.dat")));
- PrintStream outputFile;
- if(argv.length==1)
- outputFile = new PrintStream(new FileOutputStream(argv[0]));
- else
- outputFile = System.out;
- Interval i1;
- Integer min = new Integer(0);
- Integer max = new Integer(0);
- String inputFile;
- String line = null;
- while((line = file_char_stream.readLine())!= null) {
- min = min.parseInt(line);
- line = file_char_stream.readLine();
- max = max.parseInt(line);
- line = file_char_stream.readLine();
- inputFile = new String(line);
- i1 = new Interval(min, max);
- BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
- while((line = input.readLine())!= null) {
- Double x = new Double(0);
- x = x.parseDouble(line);
- i1.isInInt(x);
- }
- outputFile.println(i1.toString());
- //System.out.println(i1.toString());
- }
- outputFile.close();
- file_char_stream.close();
- //input.close();
- } catch(IOException e) {
- System.out.println("Eroare la operatiile de intrare-iesire!");
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement