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
It is a distinct type of loop, used to iterate through the properties of an object or the elements of an array. For instance assume the following statement that loops through th

Each time an object is operated in Java, it goes into the area of memory named as heap. The Java heap is named the garbage collectable heap. The garbage collection may not be force

Consider the following Java definition of an integer list class. class IntegerList { private int[] list = new int[200]; private int size = 0; public boolean append(int value) {

Java Remote Method Invocation (RMI): It gives a way for a Java program on one machine to interact with objects residing in different JVMs. The important blocks of the RMI arc

Java says write once, run anywhere . In which ways this isn't quite applicable ?

Difference between URL instance and URL Connection instance? Ans) A URL instance shows the location of a resource, and a URL Connection instance shows a link for accessing or co

Explain how several ways businesses monitor their employees? Systems are available in which monitor or most every key stroke which an employee forms on computer. Systems are av

Relate java with JVM Java performance gets better each year as JVM gets smarter. This works, since making JVM smarter doesn't require any great change to the java language, sou

What are the Design Goals of Java Massive growth of the Internet and World-Wide Web leads us to a completely new way of looking at development of software which can run on diff

Notice that each row now has the type of customer and the additional data needed. calculateBill remains the same in Customer.  However, the calculateBill in Corporate will add a