Q:

Can't use ints and sum with JOption dialog boxes

I'm using the book Java: how to program, 7th edition. The problem is that after chapter 2 it no longer gives you answers. I made an application from the book that took 2 ints from the user, and then added them together and outputted the sum with a printf display message (console app).
Now the book asks me to edit that program and use the JOption import functions (i.e. ask for the 2 integers via JOptionPane.showInputDialog("What is the first integer?"); thingy. I have to make a dialog box pop up asking for the 2 integers, and then show the sum in a messagebox at the end.
This is what I did so far, spent an hour trying to fix the errors to no avail (no clues in the book):
import javax.swing.JOptionPane;

public class Additions
{
   public static void main( String args[] )
   {
      String name1 = // return type string, pane asking for name
            JOptionPane.showInputDialog( "What is the first integer?" );

      String name2 = // return type string, pane asking for name
            JOptionPane.showInputDialog( "What is the second integer?" );

      sum = name + name2;

      String sum = String.format( "Sum is %d\n", sum );
   } 
} 

A:

You have to convert that String into an int. You can do it with this method.
String s =JOptionPane.showInputDialog( "What is the first integer?" );
int i = Integer.parseInt(s);

Take care that if the input is not an int then a NumberFormatException will be thrown.
Read api :Integer#parseInt(String)
So in your code would be something like this:
 String name1 =JOptionPane.showInputDialog( "What is the first integer?" );
 int first = Integer.parseInt(name1);
 String name2 =JOptionPane.showInputDialog( "What is the second integer?" );
 int second = Integer.parseInt(name2);
 String sum = String.format( "Sum is %d\n", first + second );
 JOptionPane.showMessageDialog(null,sum); // show output

