*HELP* Creating a program that displays a 5-option menu.

Discussion in 'Java' started by Daniel, Mar 8, 2007.

  1. Daniel

    Daniel Guest

    Hi again,
    Another problem. Whenever I try creating this menu using symbols, I
    get errors. Do I have trouble with declaring character variables? I
    don't know. If you have any input or know EXACTLY how to do this,
    please let me know! Thanks group.

    !!!!

    Write a program that displays a 5-option menu. The menu options should
    be *, /, +, -, and . After the user selects the operation, the program
    should prompt the user for two double values. The appropriate
    calculation is executed and the answer is assigned to a variable. A
    message that looks something like the following is printed -- "5 * 6 =
    30". The program should repeat until the user selects quit.
     
    Daniel, Mar 8, 2007
    #1
    1. Advertising

  2. Daniel wrote:
    > Hi again,
    > Another problem. Whenever I try creating this menu using symbols, I
    > get errors. Do I have trouble with declaring character variables? I
    > don't know. If you have any input or know EXACTLY how to do this,
    > please let me know! Thanks group.


    Why not wrap you menu creation code up in a minimal test program and
    post it? As it is, I have no idea whether you have trouble declaring
    character variables or not.

    Patricia
     
    Patricia Shanahan, Mar 8, 2007
    #2
    1. Advertising

  3. Daniel wrote:
    > Hi again,
    > Another problem. Whenever I try creating this menu using symbols, I
    > get errors. Do I have trouble with declaring character variables? I
    > don't know. If you have any input or know EXACTLY how to do this,
    > please let me know! Thanks group.


    We aren't going to tell you exactly how to do your homework. Do you have
    trouble declaring variables? How are we to know if you don't post code
    and/or error messages? Psychic ability is a myth.
    >
    > !!!!
    >
    > Write a program that displays a 5-option menu. The menu options should
    > be *, /, +, -, and . After the user selects the operation, the program
    > should prompt the user for two double values. The appropriate
    > calculation is executed and the answer is assigned to a variable. A
    > message that looks something like the following is printed -- "5 * 6 =
    > 30". The program should repeat until the user selects quit.
    >

    The project description is irrelevant to the problem.
     
    Brandon McCombs, Mar 8, 2007
    #3
  4. Daniel

    Guest

    On 7 mar, 22:47, "Daniel" <> wrote:
    > Hi again,
    > Another problem. Whenever I try creating this menu using symbols, I
    > get errors. Do I have trouble with declaring character variables? I
    > don't know. If you have any input or know EXACTLY how to do this,
    > please let me know! Thanks group.
    >
    > !!!!
    >
    > Write a program that displays a 5-option menu. The menu options should
    > be *, /, +, -, and . After the user selects the operation, the program
    > should prompt the user for two double values. The appropriate
    > calculation is executed and the answer is assigned to a variable. A
    > message that looks something like the following is printed -- "5 * 6 =
    > 30". The program should repeat until the user selects quit.



    "Whenever I try creating this menu using symbols"

    To create the menus:

    ---------------
    package javaapplication2;

    import javax.swing.*;

    /**
    *
    * @author gethostbyname
    */
    public class Menus {


    public Menus() {
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    JFrame janela = new JFrame();
    JMenuBar menuBar = new JMenuBar();

    // Menu
    JMenu menuPrincipal = new JMenu("Operações");
    menuBar.add(menuPrincipal);


    //Items do Menu criado acima
    JMenuItem m_itemSom = new JMenuItem("+");
    menuPrincipal.add(m_itemSom);

    JMenuItem m_itemSub = new JMenuItem("-");
    menuPrincipal.add(m_itemSub);

    JMenuItem m_itemDiv = new JMenuItem("/");
    menuPrincipal.add(m_itemDiv);

    JMenuItem m_itemMult = new JMenuItem("*");
    menuPrincipal.add(m_itemMult);


    //
    janela.setJMenuBar(menuBar);

    //Mostrar janela
    janela.setSize(500,500);
    janela.setVisible(true);

    janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Read http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
    }

    }
    ---------------


    I usually create them using NetBeans :)

    gethostbyname
     
    , Mar 8, 2007
    #4
  5. Daniel

    Guest

    On 7 mar, 22:47, "Daniel" <> wrote:
    > Hi again,
    > Another problem. Whenever I try creating this menu using symbols, I
    > get errors. Do I have trouble with declaring character variables? I
    > don't know. If you have any input or know EXACTLY how to do this,
    > please let me know! Thanks group.
    >
    > !!!!
    >
    > Write a program that displays a 5-option menu. The menu options should
    > be *, /, +, -, and . After the user selects the operation, the program
    > should prompt the user for two double values. The appropriate
    > calculation is executed and the answer is assigned to a variable. A
    > message that looks something like the following is printed -- "5 * 6 =
    > 30". The program should repeat until the user selects quit.


    hehehe, what does the symbol "." mean?

    gethostbyname
     
    , Mar 8, 2007
    #5
  6. Daniel

    Daniel Guest

    How's it going guys? Thanks for all the responses. Well I changed it.
    I wanted to have the Q be quit. But then when I type in Q when
    prompted, it gives me an 'error quit'.. So it ends the run but not
    exactly how I wanted. Can anyone help me so I can get 'Q' to end the
    run the right way instead of getting an error? Here's what I have by
    the way:



    public class fiveOptionMenu
    {
    public static void main(String[] args)
    {
    int selection = 0;
    double numb1 = 0.0;
    double numb2 = 0.0;
    double answer = 0.0;

    do
    {
    System.out.println( "\n \n1. * Multiplication" );
    System.out.println( "2. / Division" );
    System.out.println( "3. + Addition" );
    System.out.println( "4. - Subtraction" );
    System.out.println( "Q. To Quit" );
    System.out.println( " \n Enter your selection: ");
    selection = MyInputScanner.ReadInt();

    switch( selection )
    {
    case 1:

    System.out.println( "\n1st value - Enter the number you would like
    to multiply: ");
    numb1 = MyInputScanner.ReadDouble();
    System.out.println( "\n2nd value - Enter the value you would like to
    multiply by: ");
    numb2 = MyInputScanner.ReadDouble();
    System.out.print( "\nThe result is: ");
    answer = numb1 * numb2;
    System.out.print(answer);

    case 2:

    System.out.println( "\n1st value - Enter the value you would like to
    multiply: ");
    numb1 = MyInputScanner.ReadDouble();
    System.out.println( "\n2nd value - Enter the value you would like to
    multiply by: ");
    numb2 = MyInputScanner.ReadDouble();
    System.out.print( "\nThe result is: ");
    answer = numb1 / numb2;
    System.out.print(answer);

    case 3:

    System.out.println( "\n1st value - Enter the value you would like to
    multiply: ");
    numb1 = MyInputScanner.ReadDouble();
    System.out.println( "\n2nd value - Enter the value you would like to
    multiply by: ");
    numb2 = MyInputScanner.ReadDouble();
    System.out.print( "\nThe result is: ");
    answer = numb1 + numb2;
    System.out.print(answer);

    case 4:

    System.out.println( "\n1st value - Enter the value you would like to
    multiply: ");
    numb1 = MyInputScanner.ReadDouble();
    System.out.println( "\n2nd value - Enter the value you would like to
    multiply by: ");
    numb2 = MyInputScanner.ReadDouble();
    System.out.print( "\nThe result is: ");
    answer = numb1 - numb2;
    System.out.print(answer);

    case 'Q':
    break;
    default:
    System.out.println( "The selection you have entered was invalid. " );
    }
    } while ( selection != 'Q');
    }//end of public static void main(String[] args)
    }//end of public class fiveOptionMenu
     
    Daniel, Mar 9, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chumley Walrus
    Replies:
    1
    Views:
    12,235
    =?Utf-8?B?QnJpYW4gQnJvd24=?=
    Dec 16, 2004
  2. Bishop
    Replies:
    0
    Views:
    329
    Bishop
    Apr 16, 2006
  3. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    774
    GianGuz
    Dec 21, 2004
  4. Cas
    Replies:
    5
    Views:
    817
    Kevin Jones
    Aug 28, 2006
  5. Julia Briggs
    Replies:
    1
    Views:
    117
    Bob Bedford
    Jan 29, 2004
Loading...

Share This Page