Need the following code for double variables instead of int, JAVA Programming

Need the following code in double var instead of integer.

import javax.swing.*;

public class arrayVar
{
public static void main (String[] args)
//This is our main method prompting the user for prices and calling the
//appropiate methods
{
int[] price = new int[5];

//fill the array

for (int p=0; p < 5; p++)
{//get our values

price [p] = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter a value: "));

}//end for

int sum = sumArray(price);//call the sumArray method
int ave = aveArray(price);//call the aveArray method
int high = highPrices(price);//call the highPrices method

JOptionPane.showMessageDialog(null, "The sum of these values are $" + sum + "\nThe average of these values is: $" + ave + "\nThe values higher than the average are: " + high);

}//end main


public static int sumArray(int[] price)
{//method will receive array and return the sum of its elements. no output.
int sum = price[0];
for (int s=0; s < 5; s++)
{
sum +=price[s];

}//end for

return sum;

}//end method

public static int aveArray(int[] price)
{//method willl reveive array and return the average of its elements. no output.
int ave = price[0];
for (int a=0; a < 5; a++)
{
ave = (ave + price[a])/price.length;

}//end for

return ave;

}//end method

public static int highPrices(int[] price)
{//method receives array and an average. prints out all elements with values
//greater than the average

int ave = price[0];
int high = price[0];

for (int a=0; a < 5; a++)
{
ave = ave + price[a]/price.length;

}//end for

if (int h=0; h < 5 ; h++))
return true;
}//end method

}//end class
Posted Date: 11/20/2012 9:06:20 PM | Location : United States







Related Discussions:- Need the following code for double variables instead of int, Assignment Help, Ask Question on Need the following code for double variables instead of int, Get Answer, Expert's Help, Need the following code for double variables instead of int Discussions

Write discussion on Need the following code for double variables instead of int
Your posts are moderated
Related Questions
Objectives _ Creating and compiling a simple program _ Designing classes _ Use of recursive algorithms _ Learn basic combinatorics   Task: string permutation Writ

Sequence diagrams are communication diagrams which detail what messages are sent and when. The sequence diagrams are placed according to time. The time performs as you move from to

I want School Management project Project Description: An easy school management project which able to store all data about students like fees structure, admission details and

Staging areas that have messages those have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages don't have to be delivered in the or

1) Categorical variable tread Pattern = {A, B} and numerical variable tread Depth are used to classify Handling = {good, poor} of a vehicle. Depth is normally distributed with mean

Read information of n students. The class name should be kkhsou with the member variable name, rollno, center_code and percentage in last examestion.Display the students data whose

Java Programming 1. Write a program in Java to find the highest of any five numbers. How do you compile and execute this Java program? 2. Write a program to explain the Exce

Question : (a) Class file verification in CLDC is different from class file verification in J2SE. Explain and discuss how and why it is different, illustrating your answer

Exercise 1) Lets start by query example in SPARQL: QUERY: What are the school's names that belong to the "local authority district" 00AA? NOTE 1: "Authority districts" divide UK i

Write HTML and JavaScript code for the needs shown in the diagram below? When ConvertoUpperCase button is pressed then the entered text is converted to upper case and result is