javajgrasp

How to use JOptionPane.showMessageDialog once in the prograde


How many times have you used the statement: JOptionPane.showMessageDialog? If your answer is more than once go back and revise your code so that you only use ONE JOptionPane.showMessageDialog

Hint: consider using a variable of type String named output

Code

if(credit >= 120)

  {

     JOptionPane.showMessageDialog(null,"You've graduated!");

  }//end if

  else if(credit >= 90)

  {

     JOptionPane.showMessageDialog(null,"You're a senior.");

  }//end if

  else if(credit >= 60)

  {

     JOptionPane.showMessageDialog(null,"You're a junior.");

  }//end if

  else if(credit >= 30)

  {

     JOptionPane.showMessageDialog(null,"You're a sophomore.");

  }//end if

  else if(credit >=0)

  {

     JOptionPane.showMessageDialog(null,"You're a freshment.");

  }//end if


  else

  {
     JOptionPane.showMessageDialog(null,"invalid input");

Solution

  • Use the if-else statements to generate the String to show, then use a single line to call showMessageDialog() using the String.