Welcome to Dream.In.Code
Become a Java Expert!

Join 150,372 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,785 people online right now. Registration is fast and FREE... Join Now!




Using JOptionPane to create a double var from User

 
Reply to this topicStart new topic

Using JOptionPane to create a double var from User

bbrettdd
26 Jan, 2008 - 11:45 PM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 4


My Contributions
Hey everyone,

This is my first ever programming project, and I am having trouble taking a user's input from JOptionPane and turning it into a working double variable.

In every place that the word "input" comes up, there is an error message (in Eclipse) saying that the variable cannot be resolved (sadly, I don't know exactly what this means either). Also, because of theerror in the beginning, I haven't quite worked out the ending of it either, so just ignore that...

I hope I am overlooking something simple, but this has been giving me a big headache for the past couple of days. I appreciate the help. Thanks.



CODE

import javax.swing.JOptionPane;
public class InvoiceApp {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
        //display a welcome message
        JOptionPane.showMessageDialog(null, "Welcome to the Invoice Application");
        
        //perform calculations until choice is not "Y"
        String choice = "y";
        while (choice.equalsIgnoreCase("y"));
        {
            //get invoice sub total from the user
            input = JOptionPane.showInputDialog(null,"Please Enter Subtotal: ");
            double subTotal = Double.parseDouble(input);
            
                                                //calculate the discount amount and total
            double discountPercent = 0.0;
            if (subTotal >= 200)
                discountPercent = .2;
            else if (subTotal >= 100)
                discountPercent = .1;
            else
                discountPercent = 0.0;
            double discountAmount = subTotal * discountPercent;
            double total = subTotal - discountAmount;
            
            //display the discount amount and total
            JOptionPane.showMessageDialog(null, "Discount Percent: " + discountPercent);
            JOptionPane.showMessageDialog(null, "Discount Amount: " + discountAmount);    
            JOptionPane.showMessageDialog(null, "Invoice Total: " + total);
            
            //see if the user wants to continue
            String decision = "";
            input = JOptionPane.showInputDialog(null, "Would you like to continue?");
            
            }
        
    }

}

User is offlineProfile CardPM
+Quote Post

GWatt
RE: Using JOptionPane To Create A Double Var From User
27 Jan, 2008 - 06:07 AM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,360



Thanked: 31 times
Dream Kudos: 500
My Contributions
You haven't declared 'input' anywhere. All ou have to do is change that line to:
String input = JOptionPane.showInputDialog(null,"Please Enter Subtotal: ");
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month