Results 1 to 5 of 5

Thread: Help needed in Java for Writing an Application that reads four doubles as its input

  1. #1
    Join Date
    Jul 2006
    Posts
    182

    Help needed in Java for Writing an Application that reads four doubles as its input

    I have given a project. I need help for the same project that has to be completed soon. I have to write an application that reads four doubles as its input in Java. I am new to such scenarios. The program then displays as its output the minimum integer of the four, maximum integer of the four and then the average of the four doubles. Can someone help me by providing the codes.?? Need help as early as possible.
    "Yea though I walk through the valley of the shadow of death... I will fear no evil." -Psalms 23

    K8N Diamond Plus (BIOS v1.2)
    AMD Athlon 64 X2 4400+
    Antec TruControl 550W
    NVidia GeForce 7900GT (NGO v1.8466 BETA)
    OCZ Platinum 2x1GB (2-3-2-5)
    SATA: WD740
    PATA: 2xWD2500, WD1200, NEC DVD/RW

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Help needed in Java for Writing an Application that reads four doubles as its input

    I think that you will have to first get the input, so that you can display its output as minimum, maximum and the average integer of the four. For doing this you can either use the JOptionPane class or through system.in. You can calculate the average by adding up the four values and dividing by four once you have the four doubles stored in variables. You will have to call Math.max on the first two numbers in order to calculate the max, then you will have to store this in a temp variable. You will have to do the same procedure for the rest operations. After this you display the values, again you can use the JOptionPane class or System.out to print to the console.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Help needed in Java for Writing an Application that reads four doubles as its input

    I don't know much about Java. But I think that I can give the code for a program that takes its input from a file of numbers of type double in C++. The output is the average, variance, and standard deviation of the numbers in the file.

    #include <iostream>
    #include <fstream> //to use fstream functions
    #include <stdio.h>
    #include <string>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    int RecCount=0;
    int main()
    {
    double variance =0,standdev=0;
    string myfilename, str;
    myfilename = "test.txt";
    ifstream inFile;
    inFile.open(myfilename.c_str());
    if (!inFile)
    {
    cout <<"Error opening file " << endl;
    system("pause");
    return -1;
    }
    int elmAdditons=0,elm=0,elmPrev=0;
    cout<<"Numbers In The File As Following"<<endl;
    while (!inFile.eof()) {
    getline(inFile,str);
    cout<<str<<endl;
    elm =atoi(str.c_str());
    if(RecCount>0)
    {
    elmAdditons+= (elm-elmPrev)*(elm-elmPrev);
    }
    elmPrev=elm;

    RecCount++;

    }
    variance=( double) elmAdditons/RecCount;
    standdev=sqrt(variance);

    cout<<"Variance Is "<<variance<<endl;
    cout<<"standard deviation Is " <<standdev<<endl;
    getchar();
    }
    I think this coding will help you to clear the logic for the input from a file of numbers of type double.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Help needed in Java for Writing an Application that reads four doubles as its input

    I would like to Thanks 'Modifier', since I was searching for this code in C++ for a long time. Your work is really appreciable. I would like to suggest 'SKREECH' to search the similar topics in the Sun's website. I am sure that you will find some relevant answers over there. Also try to do the R & D even if you get some similar coding. By doing that you will improve your skills in specific programming languages.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Help needed in Java for Writing an Application that reads four doubles as its input

    I would like to suggest you to avoid use of the Math.max method since it only accepts two inputs. You have to check that number is greater than the current "greatest number". So you can just compare the number to the greatest number so far using the > operator. If it is greater then store this new number as the greatest number. By using the java.util.Scanner class, I believe that console input is most easily accomplished. Also you will have to use a for loop that iterates 4 times to accomplish this.

Similar Threads

  1. install application without writing to the registry
    By Gondar in forum Windows Software
    Replies: 7
    Last Post: 11-03-2013, 06:34 PM
  2. End user input needed for proper SATA speed database in OCZ SSD
    By Anuja Darzi in forum Hardware Peripherals
    Replies: 8
    Last Post: 13-04-2012, 02:39 PM
  3. application needed that should let users input blurbs
    By MonDo021 in forum Software Development
    Replies: 4
    Last Post: 02-04-2011, 03:39 AM
  4. Novel writing application for Apple iPad
    By Hakesh in forum Portable Devices
    Replies: 5
    Last Post: 03-03-2011, 10:27 AM
  5. Tools needed for Mobile Application Development in Java
    By Viensterrr in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 04:14 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,870,540.91596 seconds with 16 queries