Ibraheem Akbar
Ibraheem Akbar

Reputation: 1

Inserting a double variable in JOptionPane

Im new to java and im having trouble with the code below. Im trying to convert a double variable to a string variable to use it in JOptionPane.showMessagedialog but its giving me an error which is listed below.

import javax.swing.JOptionPane;
public class pricecalculatorchap5

{
   public static void main(String [] args)

   {
         String priceinput;
         double wholesaleprice;
         double markupprice;
         double retailprice;
         String retailprice2;
         String pricecalculated;

     priceinput = JOptionPane.showInputDialog("Please enter the whole sale price of the item.");
     wholesaleprice = Double.parseDouble(priceinput);


          priceinput = JOptionPane.showInputDialog("Please enter the markeup price of the item.");
          markupprice = Double.parseDouble(priceinput);


     retailprice = ( (markupprice / 100) * wholesaleprice) + wholesaleprice;
     retailprice2 = Double.toString (retailprice);



     pricecalculated = JOptionPane.showMessageDialog("The price of the item is calculated as  " +  retailprice2 );  


   }
}      

ERROR

pricecalculatorchap5.java:28: error: no suitable method found for showMessageDialog(String) pricecalculated = JOptionPane.showMessageDialog("The price of the item is calculated as " + retailprice2 );
^ method JOptionPane.showMessageDialog(Component,Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable (actual and formal argument lists differ in length) 1 error

Upvotes: 0

Views: 1829

Answers (1)

TuyenNTA
TuyenNTA

Reputation: 1204

showMessageDialog always together with a Component. There are serveral method override but none of them have only String parameter like you using. Refer Document

Upvotes: 0

Related Questions