Hi, just wondered if anyone could help, this is my college work an i have this bit of code, just wondered if anyone could help me.....
im trying to do an addition of 3 array amounts
public void AverageProduction()
{
/*Shows input dialog box asking for user to enter a name
String value declared for user input storeage*/
String category = JOptionPane.showInputDialog( "Please enter a Cider name so we can work out its average production " );
/*If statement used to return program to main start menu if cancel button is pressed*/
if(category==null)
{
Startmenu();/*Instruction to return to start menu*/
}
/*Debug line for data search.Displayed on system.out.println */
//System.out.println("The average is: ");
/*for loop used to search array index for the name entered by user
int a = storage for number of the counter for name array row
(counter for row number; while row number doesn't equal any of the Strings in the array row; add to counter to search again on next row )*/
for(int a =0;a<name.length;a++)/**/
{
/*If statement used to compare string array index storing peoples names equal(ignoring case of lettering) to input entered by the user*/
if (name[a][0].equalsIgnoreCase(category))
{
/*If the if statement is true
Debug line for data search.Displays results on system.out.println */
System.out.println("\t\t\t\t "+name[a][0]+ " \t "+name[a][1] +"\n"+weight[a][2]);
/*Shows user results in a message dialog box, displaying search row number of array String information(name and category group)*/
// JOptionPane.showMessageDialog(null,"The category group for:\n" +weight[a][0] +"\n"+weight[a][1] +"\n"+weight[a][2]);
/*Shows user results in a message dialog box, Average*/
[B][U]JOptionPane.showMessageDialog(null,"The total average is " +weight[a][0] +" + "+weight[a][1] +" + "+weight[a][2]);[/U][/B]
/*Instruction to return to the beginning of method for finding category results once results have been displayed*/
AverageProduction();
}
}
/*Debug line to display error on system.out.println*/
System.out.println(" "+ error+"\nSorry the name you entered didn't match any on file.\n"+ "Please ensure it is spelt correctly");
/*Shows user message dialog box to display error*/
JOptionPane.showMessageDialog(null," Sorry the name you entered didn't match any on file.\n" + "Please ensure it is spelt correctly"
,"Incorrect Data",JOptionPane.ERROR_MESSAGE);
/*Instruction to return to the beginning of method for finding category results once error result has been displayed*/
AverageProduction();
}
How can i get this to work? thanks :) xx
beth2138 0
Newbie Poster
Recommended Answers
Jump to PostSo just add them. I don't understand what part you are having trouble with
double total = weight[a][0] +weight[a][1] +weight[a][2];
String concatenation has nothing at all to do with math operations on variables.
Jump to PostJust loop through the array and have a variable that keeps track of the highest. If the current array element is greater than that value, set the value to that elements value.
All 8 Replies
beth2138 0
Newbie Poster
beth2138 0
Newbie Poster
Ezzaral 2,714
Posting Sage Team Colleague Featured Poster
beth2138 0
Newbie Poster
Ezzaral 2,714
Posting Sage Team Colleague Featured Poster
beth2138 0
Newbie Poster
beth2138 0
Newbie Poster
VernonDozier 2,218
Posting Expert Featured Poster
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.