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

D

Daniel

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.
 
P

Patricia Shanahan

Daniel said:
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
 
B

Brandon McCombs

Daniel said:
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.
 
G

gethostbyname

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
 
G

gethostbyname

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
 
D

Daniel

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top