I'm trying to write a Java application that will read five double values and find the total, average, minimum and maximum of the values entered. For some reasons after trying to find what wrong with it it's still not building. I'd appreciate someone's expertise on the matter.

import javax.swing.JOptionPane;

class minmax {
   /** Main Method */
   public static void main(String[] args){      
     final int TOTAL_NUMBERS = 5;
     int[] numbers = new int[5,10, 15, 20, 25,];

     // Read all numbers
     for (int i =0; i < numbers.length;i++) {
       String numString = JOptionPane.showInputDialog(null,
         "Enter a value:",
         "Input", JOptionPane.QUESTION_MESSAGE);


     // Find the largest 
     int max = numbers[0];
     for (int i = 1; i < numbers.length; i++) {
       if (max < numbers[i])
         max = numbers[i];
     }

    // Find the smallest 
    int min = numbers[0];
    for (int i = 1; i > numbers.length; i++) {
      if (min > numbers[i])
        min = numbers[i];
     }


     //Get average 
     double getAverage = Double.parseDouble(doubleString); 
        return (value A + value B + value C + value D + valueE) / 5; 

     //Determine the total of the five values 
     double determinetotal = Double.parseDouble(doubleString);
        return (value A + value B + value C + value D + value E);       

    // Prepare the results 
    String output = "The values are  ";
    for (int i = 0; i < numbers. length; i++0 {
      output += numbers[i] + " ";
     }

    output += "\nThe largest number is " + max;  
    output += "\nThe smallest number is " + min;
    output += "\nThe average number is " + average;
    output += "\nThe total number is " + total;

    // Display results     
    JOptionPane.showMessageDialog(null,output,
       "Output", JOptionPane.INFORMATION_MESSAGE);
  }
 }

Recommended Answers

All 4 Replies

What is the error you're receiving when you try and compile?

hooknc: What is the error you're receiving when you try and compile?[/QUOTE]

After making some additional modifcations it still not compiling due to the last bracket. Here is the error message I receiving with revised
code.

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\HP_Administrator\JavaApplication7\build\classes
C:\Documents and Settings\HP_Administrator\JavaApplication7\src\javaapplication7\Main.java:56: '}' expected
1 error
BUILD FAILED (total time: 0 seconds)

Code:

import javax.swing.JOptionPane;

class minmax {
   /** Main Method */
   public static void main(String[] args)
   {
     final int TOTAL_NUMBERS = 5;
     int[] numbers = new int[5+ 10 + 15 + 20 + 25];

     // Read all numbers
     for (int i =0; i < numbers.length;i++) {
       String numString = JOptionPane.showInputDialog(null,
         "Enter a value:",
         "Input", JOptionPane.QUESTION_MESSAGE);


     // Find the largest 
     int max = numbers[0];
     for (int i = 1; i < numbers.length; i++) {
       if (max < numbers[i])
         max = numbers[i];
     }

    // Find the smallest 
    int min = numbers[0];
    for (int i = 1; i > numbers.length; i++) {
      if (min > numbers[i])
        min = numbers[i];
     }

     //Get average 
     double getAverage = Double.parseDouble(doubleString); 
        return (5 + 10 + 15 +20 + 25) / 5; 

     //Determine the total of the five values 
     double determinetotal = Double.parseDouble(doubleString);
        return (5 + 10 + 15 + 20 + 25);       

    // Prepare the results 
    String output = "The values are  ";
    for (int i = 0; i < numbers. length; i++) {
      output += numbers[i] + " ";
     }

    output += "\nThe largest number is " + max;  
    output += "\nThe smallest number is " + min;
    output += "\nThe average number is " + average;
    output += "\nThe total number is " + total;

    // Display results     
    JOptionPane.showMessageDialog(null,output,
       "Output", JOptionPane.INFORMATION_MESSAGE);
     }

  }

Hi everyone,

After making some additional modifcations it still not compiling due to the last bracket.

I decided to redo your program and it now compiles but try and make your program a bit easier to read next time as i find it a bit cluttered.

Here is your redone progra,

import javax.swing.JOptionPane;

class minmax 
{
	int[] numbers = {
		5, 10, 15, 20, 25
	}
	;

	int getLargest(int[] num1)
	{
		// Find the largest 

		int max = num1[0];

		for (int i = 1; i < num1.length; i++) 
		{

			if (max < num1[i])
			{
				max = num1[i];
			}

		}

		return max;
	}

	int getSmallest(int[] num2)
	{
		int min = num2[0];

		for (int i = 1; i > num2.length; i++) 
		{

			if (min > num2[i])
			{
				min = num2[i];
			}

		}

		return min;
	}

	int getTotal(int[] num3)
	{

		int Total = 0;

		for(int i=0;i<num3.length;i++)
		{
			Total = num3[i] + Total;
		}

		return Total;
	}

	double getAverage(int[] num4)
	{
		int Total = getTotal(num4);
		double Avg = (Total/num4.length);

		return Avg;
	}

	void readValues()
	{
		String numString = null;

		for (int i =0;i< numbers.length;i++) 
		{
			numString = JOptionPane.showInputDialog(null,
			"Enter a value:",
			"Input", JOptionPane.QUESTION_MESSAGE);

			numbers[i] = Integer.parseInt(numString);
		}

	}

	void output()
	{
		//call the appropriate function and you are all set
	}

	public static void main(String[] args)
	{
		minmax minmax1 = new minmax();
		minmax1.output();
	}
}

I hope this has helped you

Yours Sincerely

Richard West

Thanks for your assistance Mr. West.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.