Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > *HELP* Creating a program that displays a 5-option menu.

Reply
Thread Tools

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

 
 
Daniel
Guest
Posts: n/a
 
      03-08-2007
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.

 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      03-08-2007
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
 
Reply With Quote
 
 
 
 
Brandon McCombs
Guest
Posts: n/a
 
      03-08-2007
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.
 
Reply With Quote
 
gethostbyname@gmail.com
Guest
Posts: n/a
 
      03-08-2007
On 7 mar, 22:47, "Daniel" <(E-Mail Removed)> 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_CLO SE);
// Read http://java.sun.com/docs/books/tutor...ents/menu.html
}

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


I usually create them using NetBeans

gethostbyname

 
Reply With Quote
 
gethostbyname@gmail.com
Guest
Posts: n/a
 
      03-08-2007
On 7 mar, 22:47, "Daniel" <(E-Mail Removed)> 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

 
Reply With Quote
 
Daniel
Guest
Posts: n/a
 
      03-09-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Classic asp date displays- changing over to aspnet date object displays Chumley Walrus ASP .Net 1 12-16-2004 09:57 PM
how eBay displays image previews -- assistance in re-creating Julia Briggs Javascript 1 01-29-2004 05:11 PM
Creating HTML image displays Todd Cary Digital Photography 7 11-28-2003 02:33 PM
Creating HTML image displays [with URL] Todd Cary Digital Photography 3 11-16-2003 08:22 PM



Advertisments