Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-01-2010
Member
 
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
Reply With Quote
  #2  
Old 16-01-2010
Member
 
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.
Reply With Quote
  #3  
Old 16-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #4  
Old 16-01-2010
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 16-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Help needed in Java for Writing an Application that reads four doubles as its input"
Thread Thread Starter Forum Replies Last Post
install application without writing to the registry Gondar Windows Software 7 11-03-2013 06:34 PM
End user input needed for proper SATA speed database in OCZ SSD Anuja Darzi Hardware Peripherals 8 13-04-2012 02:39 PM
application needed that should let users input blurbs MonDo021 Software Development 4 02-04-2011 03:39 AM
Novel writing application for Apple iPad Hakesh Portable Devices 5 03-03-2011 10:27 AM
Tools needed for Mobile Application Development in Java Viensterrr Software Development 5 23-01-2010 04:14 PM


All times are GMT +5.5. The time now is 01:54 AM.