Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Daniel - 08 Mar 2007 01:47 GMT
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.
Patricia Shanahan - 08 Mar 2007 02:03 GMT
> 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
Brandon McCombs - 08 Mar 2007 02:16 GMT
> 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.

> !!!!
>
[quoted text clipped - 4 lines]
> 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.
gethostbyname@gmail.com - 08 Mar 2007 02:56 GMT
> Hi again,
> Another problem. Whenever I try creating this menu using symbols, I
[quoted text clipped - 10 lines]
> 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
gethostbyname@gmail.com - 08 Mar 2007 02:58 GMT
> Hi again,
> Another problem. Whenever I try creating this menu using symbols, I
[quoted text clipped - 10 lines]
> 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
Daniel - 09 Mar 2007 17:00 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.