Home > Software engineering >  Assignment that I ran stops working after first InputDialog, how could I fix it?
Assignment that I ran stops working after first InputDialog, how could I fix it?

Time:10-03

import javax.swing.JOptionPane;
import java.util.Scanner;

public class ShippingCost
{ 
   public static void main(String[] args) 
   {
      Scanner input= new Scanner(System.in);
      JOptionPane.showInputDialog("Please enter the length of your package: ");
      double length=input.nextDouble();
 
      JOptionPane.showInputDialog("Please enter the width of your package: ");
      double width=input.nextDouble();
 
      JOptionPane.showInputDialog("Please enter the height of your package: ");
      double height=input.nextDouble();
 
      double dimensions= length * width * height;
      System.out.println("The total dimensions of your package is: "   dimensions);
      
      double charge=0;
      double surcharge;
      double additionalCharge;
      double totalCost;
 

Code compiles just fine, however running it as an application to test out the inputs is where I run into the issue that I have. First input box appears, then won't do anything else after hitting enter. I'm super new the Java and only stuck on this...

CodePudding user response:

You should use the return value of JOptionPane.showInputDialog to get the user's inputs, e.g.

double length = Double.valueOf(JOptionPane.showInputDialog("Please enter the length of your package: "));

and so on.

  • Related