Hi, i am having trouble with an assignment. i need to create an array, store numbers in the array... sqaure, cube and square root those numbers individually using different methods. display the resuts with a dialog box. after that i need to find the sum of the numbers in the array and the average, and also display that with a dialog box. when that is done i need to ask the user if they want to play again, if they answer yes, to restart the program.
the problem i am having is creating a void method that finds the sum and average of the numbers in the array. method must be a void for this task. (my lecturer said to use a for loop but i can't get it to work)
can someone please help? i'm new to this so, sorry for a lack of explanation.
/**
* Write a description of class sqaurerootCube here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class sqaurerootCube
{
public static void main (String[]args)
{
DecimalFormat fmt = new DecimalFormat ("0.##");
int num = 0;
do
{
String number = JOptionPane.showInputDialog("How many numbers do you want to enter?");
try
{
num = Integer.parseInt(number);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog (null, "That is not an integer");
}
}
while(num <0 );
String num1;
double[] numbers ;
numbers = new double[num];
for(int count = 0; count <= (num-1); count++)
{
num1 = JOptionPane.showInputDialog("Enter number "+ (count+1) + " between 25 and 150");
numbers[count]= Integer.parseInt(num1);
}
for(int count = 0; count<= (num-1); count++)
{
JOptionPane.showMessageDialog (null, "number " + (count+1)+ " sqaured = " + calcSqaure(numbers[count])+ "\nnumber " + (count+1)+ " cubed = "+ calcCube(numbers[count]) + "\nsqaure root of number "+(count+1)+" = "+ fmt.format(calcSqaureRoot(numbers[count])));
}
}
public static double calcSqaure(double x)
{
return Math.pow (x,2);
}
public static double calcCube(double x)
{
return Math.pow (x,3);
}
public static double calcSqaureRoot(double x)
{
return Math.pow (x,0.5);
}
public static void average()
{
}
}