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 8 of 8

Thread: I have a problem with this Joption programme.

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default I have a problem with this Joption programme.

    I'm trying to create program that allows you to enter a 12 digit number, e.g. xxxxxxxxxxxy... then it asks you to verify the number (but this time you only enter the first 11 digits of the same number) e.g. xxxxxxxxxxx. Then it will take the last digit of the first entry and put it together with at the end of the second entry so it can give you the full 12 digit number.
    If the numbers match it will tell you the ticket is valid.. if not it will tell you the ticket is invalid.

    Alright this is the code... When i compile it i get 14 errors:

    import javax.swing.JOptionPane;
    import javax.swing.JFrame;
     
    public Validation
    {
    public static void main(String[] args) throws Exception
    {
    //Declaration of strings
    String inputOne;
    String inputTwo;
     
    //Declaration of long numbers
    long ticket;
    long confirm;
     
    //Declaration of integers
    int remainder = ticket%10;
     
    inputOne=JOptionPane.showInputDialog("Please enter the 
     
    ticket number: ");
    inputTwo=JOptionPane.showInputDialog("Please confirm the 
     
    ticket number: ");
     
    ticket=long.parseLong(inputOne);
    confirm=long.parseLong(inputTwo);
     
    if ((confirm+remainder)==ticket)
    {
    JOptionPane.showMessageDialog(null, "The ticket number you 
     
    just entered is valid", JOptionPane.INFORMATION_MESSAGE);
    }
    else
    {
    JOptionPane.showMessageDialog(null, "The ticket number you 
     
    just entered is invalid", JOptionPane.INFORMATION_MESSAGE);
    }
    {
    System.exit(0);
    }
    }
    }
    Last edited by KevinWorkman; April 11th, 2011 at 12:39 PM. Reason: added highlight tags


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I have a problem with this Joption programme.

    And what errors might these be? On what lines?

    I've edited your post to include highlight tags. Please be more mindful in the future.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: I have a problem with this Joption programme.

    Oh sorry... And thanks.. It's my first time ever using this site or ever posting to a forum.

    This is what I get:

    C:\Program Files\Java\jdk1.6.0_24\bin>javac Validation.java
    Validation.java:4: class, interface, or enum expected
    public Validation
    ^
    Validation.java:6: class, interface, or enum expected
    public static void main(String[] args) throws Exception
    ^
    Validation.java:10: class, interface, or enum expected
    String inputTwo;
    ^
    Validation.java:13: class, interface, or enum expected
    long ticket;
    ^
    Validation.java:14: class, interface, or enum expected
    long confirm;
    ^
    Validation.java:17: class, interface, or enum expected
    int remainder = ticket%10;
    ^
    Validation.java:19: class, interface, or enum expected
    inputOne=JOptionPane.showInputDialog("Please enter the ticket number: ");
    ^
    Validation.java:20: class, interface, or enum expected
    inputTwo=JOptionPane.showInputDialog("Please confirm the ticket number: ");
    ^
    Validation.java:22: class, interface, or enum expected
    ticket=long.parseLong(inputOne);
    ^
    Validation.java:23: class, interface, or enum expected
    confirm=long.parseLong(inputTwo);
    ^
    Validation.java:25: class, interface, or enum expected
    if ((confirm+remainder)==ticket)
    ^
    Validation.java:28: class, interface, or enum expected
    }
    ^
    Validation.java:32: class, interface, or enum expected
    }
    ^
    Validation.java:35: class, interface, or enum expected
    }
    ^
    14 errors

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I have a problem with this Joption programme.

    Did you google these Exceptions?

    Hint: What does a class declaration look like?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: I have a problem with this Joption programme.

    Im really sorry. I just started java two weeks back. Im not quite sure I understand what you mean

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Apr 2011
    Posts
    18
    My Mood
    Nerdy
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: I have a problem with this Joption programme.

    Gosh, I'm such an idiot.. i forgot the "class"... This is quite different from the Visual Basic I used last year.

  8. #8
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: I have a problem with this Joption programme.

    Quote Originally Posted by Leprechaun_hunter View Post
    Gosh, I'm such an idiot.. i forgot the "class"... This is quite different from the Visual Basic I used last year.
    Now you know I've marked this thread as Solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. While loop crashing my programme?
    By livewires in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 19th, 2011, 12:36 PM
  2. help with bookfinder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 02:15 PM
  3. Help with my Range Finder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 01:53 PM
  4. Simple Programme for Date
    By bhavinsparikh in forum Java Theory & Questions
    Replies: 1
    Last Post: August 28th, 2010, 07:24 AM
  5. JOption Pane help
    By dallas1125 in forum AWT / Java Swing
    Replies: 5
    Last Post: November 18th, 2009, 05:08 PM