Question about BufferedReader

Hi, I'm trying to finish a program and need to use the BufferedReader class. I can't remember how to use/implement it and I need to design an application that reads any number of doubles, using the BufferedReader class, and calculates the average, minimum and max.

Can anyone help here?


THANKS IN ADVANCE!

Comments

  • : Hi, I'm trying to finish a program and need to use the BufferedReader class. I can't remember how to use/implement it and I need to design an application that reads any number of doubles, using the BufferedReader class, and calculates the average, minimum and max.
    :
    : Can anyone help here?
    :
    :
    : THANKS IN ADVANCE!
    :


    There are already made console packages or GUI packages
    that let you read numbers(Int, doubles etc), Strings and many more.
    The implementation depends on how it was design. But normally they
    cannot make calculations for you. you have to state the function you
    want it to perform.
    If you mean this is the type of package you need, then I can provide you
    some (From simple to more sofisticated).
    If on the other hand you have this package but don't know how to use it, then I will suggest you read the authors guide lines. It shouldn't be difficult. Or you can post it here and the board can help you.

    bashiro

  • hello . as far as i understand ur problem. i m giving u the code which uses bufferedreader class, taking double and providing the average in double too. if this is not ur problem then rephrase it. i might help u
    import java.io.*;
    class reader
    {
    public static void main(String args[])throws IOException
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("ENTER ANY THREE NUMBERS");
    double x1 = Double.parseDouble (br.readLine());
    double x2 = Double.parseDouble(br.readLine());
    double x3 = Double.parseDouble (br.readLine());

    System.out.println("The average of these numbers is "+(x1+x2+x3)/3);
    }
    }
    hope it will help u.
    FYNE
    : : Hi, I'm trying to finish a program and need to use the BufferedReader class. I can't remember how to use/implement it and I need to design an application that reads any number of doubles, using the BufferedReader class, and calculates the average, minimum and max.
    : :
    : : Can anyone help here?
    : :
    : :
    : : THANKS IN ADVANCE!
    : :
    :
    :
    : There are already made console packages or GUI packages
    : that let you read numbers(Int, doubles etc), Strings and many more.
    : The implementation depends on how it was design. But normally they
    : cannot make calculations for you. you have to state the function you
    : want it to perform.
    : If you mean this is the type of package you need, then I can provide you
    : some (From simple to more sofisticated).
    : If on the other hand you have this package but don't know how to use it, then I will suggest you read the authors guide lines. It shouldn't be difficult. Or you can post it here and the board can help you.
    :
    : bashiro
    :
    :

  • Yes, I understand your code, but mine has to run for x amount of numbers.. like using a while (line != null) type thing.
    I need to design an application that reads ANY number of doubles from the keyboard, using the BufferedReader class, and calculates the average, minimum and max.
    Can you help me there?
    -------------------------------------



    : hello . as far as i understand ur problem. i m giving u the code which uses bufferedreader class, taking double and providing the average in double too. if this is not ur problem then rephrase it. i might help u
    : import java.io.*;
    : class reader
    : {
    : public static void main(String args[])throws IOException
    : {
    : BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    : System.out.println("ENTER ANY THREE NUMBERS");
    : double x1 = Double.parseDouble (br.readLine());
    : double x2 = Double.parseDouble(br.readLine());
    : double x3 = Double.parseDouble (br.readLine());
    :
    : System.out.println("The average of these numbers is "+(x1+x2+x3)/3);
    : }
    : }
    : hope it will help u.
    : FYNE

    THANKS IN ADVANCE!

  • : Yes, I understand your code, but mine has to run for x amount of numbers.. like using a while (line != null) type thing.
    : I need to design an application that reads ANY number of doubles from the keyboard, using the BufferedReader class, and calculates the average, minimum and max.
    : Can you help me there?
    : -------------------------------------
    :
    : it ssimple selection sorting and i think it will fulfill ur needs but if u still have probelm u can ask me..
    :
    : import java.io.*;
    class ArraySel
    {
    private double[] a;
    private int nElems;

    public ArraySel(int max)
    {
    a= new double[max];
    nElems = 0;
    }

    public void insert(double value)
    {
    a[nElems] = value;
    nElems++;
    }
    public void display()
    {
    double temp=0;
    System.out.print("the largest element is "+a[0] + " and smallest element is "+a[nElems-1]);
    System.out.println("");
    for(int j=0;j<=nElems;j++)
    temp = temp+a[j];
    temp = temp/nElems;
    System.out.println("THE AVERAGE OF THE VALUES IS "+temp);

    }


    public void selectionSort()
    {
    int out, in, min;
    for( out= 0; out < nElems-1; out++)
    {
    min = out;
    for (in = out +1; in<nElems; in++)
    if(a[in] > a[min])
    min = in;
    swap(out, min);

    }
    }

    private void swap(int one, int two)
    {
    double temp = a[two];
    a[two] = a[one];
    a[one]= temp;
    }
    }

    class sel
    {
    public static void main(String args[]) throws IOException
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("");
    System.out.println("Enter the size of data you want to work on! ");
    int x= Integer.parseInt(br.readLine());

    int maxSize = 100;
    ArraySel arr;
    arr = new ArraySel(maxSize);
    System.out.println("NOW ENTER THE VALUES.");
    for (int k = 1; k<=x; k++)
    {
    double m = Integer.parseInt(br.readLine());

    arr.insert(m);
    }



    arr.selectionSort();
    arr.display();

    }
    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories