Can you help me modify this program so that it contains loops within loops somewhere. I have a while loop but that is only one. To pass my task my program MUST contain Loops Within Loops somewhere. Thank you.
import javax.swing.*;
class team
{
public static void main (String[] param)
{
insultme();
System.exit(0);
} // END main
/* *********************************
A method that asks to insult you
*/
public static void insultme()
{
// Declare variables
String textinput; // whatever the person types
int number1; // goals scored
int number2; // goals scored
String Team1 = "";
String Team2 = "";
// Get some text (a string) from the user then
// convert (known as parsing) it into a number version
while (!Team1.equals("quit"))
{
Team1 = TeamName();
if (Team1.equals("quit"))
{
break;
}
textinput = JOptionPane.showInputDialog( "Score of Team?");
number1 = Integer.parseInt(textinput);
Team2 = TeamName();
textinput = JOptionPane.showInputDialog( "Score of Team?");
number2 = Integer.parseInt(textinput);
//test score here:
testScore(Team1, Team2, number1, number2);
} //end while
return;
}//end method
/***********************************
* Method to check score and either ask for re-entry if invalid or print result.
*/
public static void testScore(String Team1, String Team2, int number1, int number2)
{
if(number1 < number2)
{
JOptionPane.showMessageDialog( null, Team2 + " won " + number2 + "-" + number1 + " against " + Team1);
}
else if (number2 < number1)
{
JOptionPane.showMessageDialog( null, Team1 + " won " + number1 + "-" + number2 + " against " + Team2);
}
else
{
JOptionPane.showMessageDialog( null, "This score is wrong, please enter a correct score");
String textinput = JOptionPane.showInputDialog( "Score of Team 1 again");
number1 = Integer.parseInt(textinput);
textinput = JOptionPane.showInputDialog( "Score of Team 2 again");
number2 = Integer.parseInt(textinput);
testScore(Team1, Team2, number1, number2); // call method if re-entry
}
} //end method
/* *********************************
*/
public static String TeamName()
{
return JOptionPane.showInputDialog("Team Name?");
}
} // END class team