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

Thread: Joptionpanel. i need help here.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Joptionpanel. i need help here.

     
    Can you once more help me please?
    Attached Images Attached Images

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    Please copy the text and paste it here. No images of text.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    jasonLee01 (October 25th, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    // TODO code application logic here
    double price1 = 29.0;
    double price2 = 39.0;
    double price3 = 49.0;
    double total=0.0;
    int item=0;
    Scanner input = new Scanner (System.in);
    int counter = 0;
    int select;
    String str;
    String menu;
    str=JOptionPane.showInputDialog(null, "(1) Phone Casing \t\tRM29.90\n(2) Bluetooth Speaker \t\tRM39.00\n(3) Power Bank \t\tRM49.95\nMake selection.Press 0 to quit.",
    "Input",
    JOptionPane.QUESTION_MESSAGE);

    do{
    select = input.nextInt();
    if (select == 1);
    total=total+price1
    else if(select == 2);
    total=total+price2
    else if(select == 3);
    total=total+price3
    else if (select==0)
    break;
    Counter++;
    item++

    JOptionPane.showMessageDialog (
    null, "You have selected" + item + "item with ",
    JOptionPane.PLAIN_MESSAGE);
    System.exit ( 0 );
    }

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    Did you have a question?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    jasonLee01 (October 25th, 2013)

  7. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    This is the code i do, but got some problem there.
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package javaapplication1;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
     /**
      *
     * @author student
     */
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            double price1=29.0;
            double price2=39.0;
            double price3=49.0;
            double total=0.0;
            int item=0;
            Scanner input = new Scanner (System.in);
            int counter = 0;
            int select;
            do{
                System.out.print("Enter ther selection: ");
                select = Input.nextint();
              if (select==1);
                total=total+price1
                else if(select == 2);
                total=total+price2
                else if(select == 3);
                total=total+price3
                 else if (select==0)
                break;
                Counter++;
                item++
                System.out.println("You have selected" + item + "item with "
                        while(counter<4);
                system.out.println(String.format("%3", total) )
     
            }
    Last edited by Norm; October 25th, 2013 at 05:43 PM. Reason: QUOTE tag changed to code

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    got some problem there.
    Please explain.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    jasonLee01 (October 25th, 2013)

  10. #7
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    383
    My Mood
    Angry
    Thanks
    46
    Thanked 63 Times in 63 Posts

    Default Re: Joptionpanel. i need help here.

    item++
    System.out.println("You have selected" + item + "item with "
    while(counter<4);
    system.out.println(String.format("%3", total) )


    You have no ; after item++


    Your second line doesn't have an ending );

    You need to capitalize System.


    Also, your ; is what is being executed after your if statements. You should get rid of that ;. You don't need it right after an if. You need a bracket to end your do....while loop but you don't have one.


    You do need a ; after statements like

    total=total+price1


    Java is case-sensitive when it comes to variable names so it won't like it if you name your Scanner object input and then put this:

    select = Input.nextint();

    Also, the Scanner method is called nextInt(), not nextint().


    ----------Update-------------
    I think I see what you're wanting to do.

    You want to use JOptionPane instead of Scanner.

    Your JOptionPane method returns a String.

    The Integer class has a static method called parseInt(String) that parses a String and converts it, if possible, to an int and returns that int.
    JavaScript is NOT Java.

  11. The Following User Says Thank You to GoodbyeWorld For This Useful Post:

    jasonLee01 (October 25th, 2013)

  12. #8
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    Prompt the user to choose an product using the number (1,2,3) that
    corresponds to the item, or to enter 0 to quit the application. After the user
    makes the first selection, if the choice is 0, display a bill of RM0. Otherwise,
    display the menu again.
    o Use other store for example: restaurant, boutique or fruit stalls with
    different product and prices.
    o *minimum 3 products as the selections
    The last question is like this:
    The user should respond to this prompt with another item number to order or 0
    to quit. If the user types 0, display the cost of the single request item. If the
    user types 1, 2, or 3 add the cost of the second item to the first, and then
    display the menu a third time. If the user types 0 to quit, display the total cost
    of the two items; otherwise, display the total for all three selections and the
    total item purchased. The user is only allowed to make a maximum of 3 menu
    selections.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package javaapplication1;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
     /**
      *
     * @author student
     */
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            double price1=29.0;
            double price2=39.0;
            double price3=49.0;
            double total=0.0;
            int item=0;
            Scanner input = new Scanner (System.in);
            int counter = 0;
            int select;
            do{
             user_value = JOptionPane.showInputDialog("Enter temperature: ");
             value = Integer.parseInt(user_value);
     
              if (select==1);
                total=total+price1;
                else if(select == 2);
                total=total+price2;
                else if(select == 3);
                total=total+price3;
                 else if (select==0)
                break;
                Counter++;
                item++;
                System.out.println("You have selected" + item + "item with "
                        while(counter<4);
                system.out.println(String.format("%3", total) )
    JOptionPane.showMessageDialog (
    null, "You have selected" + item + "item with "(String.format("%3", total) ),
    JOptionPane.PLAIN_MESSAGE);
    System.exit ( 0 ); 
     
            }
     
            }
    Last edited by Norm; October 25th, 2013 at 06:36 PM. Reason: replaced quote with code tags

  13. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    You need to ask specific questions about the problems you are having.

    Be sure to use code tags NOT quote tags
    If you don't understand my answer, don't ignore it, ask a question.

  14. The Following User Says Thank You to Norm For This Useful Post:

    jasonLee01 (October 25th, 2013)

  15. #10
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    the code not working.got error there,
    somewhere.
    on the Prompt the user to choose.
    and The user should respond to this prompt with another item number to order or 0
    to quit.

  16. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    If there are any compiler errors, please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #12
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    for the question,
    1. Prompt the user to choose an product using the number (1,2,3) that
    corresponds to the item, or to enter 0 to quit the application. After the user
    makes the first selection, if the choice is 0, display a bill of RM0. Otherwise,
    display the menu again.
    o Use other store for example: restaurant, boutique or fruit stalls with
    different product and prices.
    o *minimum 3 products as the selections



    2.The user should respond to this prompt with another item number to order or 0
    to quit. If the user types 0, display the cost of the single request item. If the
    user types 1, 2, or 3 add the cost of the second item to the first, and then
    display the menu a third time. If the user types 0 to quit, display the total cost
    of the two items; otherwise, display the total for all three selections and the
    total item purchased. The user is only allowed to make a maximum of 3 menu
    selections.
    Come out this,
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package javaapplication10;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    /**
     *
     * @author Jason_PC
     */
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    public class JavaApplication10 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            double price1=29.0;
            double price2=39.0;
            double price3=49.0;
            double total=0.0;
            int item=0;
            Scanner input = new Scanner (System.in);
            int counter = 0;
            int select;
            do{
                System.out.print("Enter ther selection: ");
                select = Input.pase
              if (select==1);
                total=total+price1
                else if(select == 2);
                total=total+price2
                else if(select == 3);
                total=total+price3
                 else if (select==0)
                break;
                Counter++;
                item++
                JOptionPane.showOptionDialog("You have selected" + item + "item with "
                        while(counter<4);
                JOptionPane.showOptionDialog(String.format("%3", total) )
     
            }
     
            }


    With have this error warning.
    run:
    java.lang.ClassFormatError: Duplicate field name&signature in class file javaapplication10/JavaApplication10
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :792)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:482)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    Can anyone help me.
    Last edited by Norm; October 30th, 2013 at 02:59 PM. Reason: change quote to code tags

  18. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    I don't know what the error you posted means. I've never seen one like it.

    The posted code does not compile without many errors. You need to copy the full text of the compiler's error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  19. The Following User Says Thank You to Norm For This Useful Post:

    jasonLee01 (October 30th, 2013)

  20. #14
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Joptionpanel. i need help here.

    where can i get the compile code.sorry, i new in java.

  21. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,272
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Joptionpanel. i need help here.

    The javac compiler comes in the JDK that is a free download from the Oracle site.
    Do a Search for JDK Download and the search engine will give you the URL where the JDK can be downloaded.

    run:
    java.lang.ClassFormatError: Duplicate field name&signature in class file
    How did you get that error message? What program did you execute?
    If you don't understand my answer, don't ignore it, ask a question.