954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Build Failed Issues..

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);
}
}

ben1977
Newbie Poster
4 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

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

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 
What is the error you're receiving when you try and compile?

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)

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);
}

}

ben1977
Newbie Poster
4 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

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

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

Thanks for your assistance Mr. West.

ben1977
Newbie Poster
4 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You