Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Simple programming help

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Simple programming help

    Okay so I am required to enter an decimal amount such as "7.53" via JOptionPane and echo that by System.out.println

    I have the start of the code here, but It gives me an error when i enter (7.53) as my input.. how can i input it in decimal form?



    import javax.swing.*;

    public class A1Q1 {
    public static void main (String [] args) {

    //Declaring Variables Here
    String userInput;
    double amount;
    double amount2;
    double toonies = 2.00;
    double loonies = 1.00;
    double quarters = 0.25;
    double dimes = 0.10;
    double nickles = 0.05;
    double pennies = 0.01;
    int mydoub;
    //Accepting User Input
    userInput = JOptionPane.showInputDialog(null,"Please enter an amount");
    amount = Integer.parseInt(userInput);

    }

    }
    THIS IS MY INTERACTION PANE



    java.lang.NumberFormatException: For input string: "7.53"
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:458)
    at java.lang.Integer.parseInt(Integer.java:499)
    at WahidMuhammadA1Q1.main(WahidMuhammadA1Q1.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at edu.rice.cs.drjava.model.compiler.JavacCompiler.ru nCommand(JavacCompiler.java:272)
    >


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Simple programming help

    What type is the variable amount?
    What method are you calling?

    --- Update ---

    OK

    I see you have managed to solve your problem and ask another question in a new thread. Thanks for letting us know.
    Improving the world one idiot at a time!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Simple programming help

    Please read the Announcement at the top of the sub-Forums to learn how to post your code in code/formatting tags and how to ask questions that get attention and receive helpful answers.

Similar Threads

  1. Programming AI for simple game?
    By YouGoLast in forum Java Theory & Questions
    Replies: 3
    Last Post: September 27th, 2024, 02:33 AM
  2. Replies: 3
    Last Post: September 23rd, 2013, 10:51 AM
  3. Programming Issues simple Game
    By NaeGuk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 10th, 2013, 10:07 AM
  4. Blackjack programming error (programmer is new to programming)
    By JSingh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 09:13 PM
  5. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM