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

Assignment Help:
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

Related Discussions:- Need the following code for double variables instead of int

Explain the use and purpose of java adapter classes, Question: (a) Exp...

Question: (a) Explain the event handling mechanism using a 'JComboBox' as example. Your answer must clearly indicate the event source, event object and event listener. Also

Compare classes of java with c++, Compare classes with C++ Some signif...

Compare classes with C++ Some significant points to consider when defining a class in java as you probably noticed from above given skeleton are -  There  are  no  global

Why we avoiding short circuits, Why we Avoiding Short Circuits ? If you...

Why we Avoiding Short Circuits ? If you need all of your boolean expressions evaluated regardless of the truth value of each, then you can use & and | instead of && and ||. The

Explain system colors in java 1.1, Explain System Colors in java 1.1? I...

Explain System Colors in java 1.1? In Java 1.1, the java.awt.SystemColor class is a subclass of java.awt.Color that gives color constants in which match native component colors

What are the non-final functions in java object class?, The non-final funct...

The non-final functions are clone (), finalize (), toString (), equals () , hashCode () and. The other methods like wait (), getClass (), notifyAll (), notify () etc are final

Prepare a java program, Using Java, write the class Time which consists of ...

Using Java, write the class Time which consists of the following: (a) three private integer data members (hours, minutes and seconds). (b) a constructor to initialise the dat

What is application context module, The Application context module makes sp...

The Application context module makes spring a framework. This module extends the concept of BeanFactory, giving support for internationalization (I18N) messages, application lifecy

While statement in java, The while statement define a loop that iterates as...

The while statement define a loop that iterates as long as condition remains true. In the following instance the control waits till the value of a text field becomes "go":

Tasks with the classes Currency, In this assignment you work on a set of ta...

In this assignment you work on a set of tasks with the classes Currency, Money and Bank. Money and Currency You have been given a template for the Currency and Money classes (Lab1.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd