i cant make a code about

Using JOptionPane

Posted 19 August 2010 - 07:24 AM

Write a program called MinMaxAvg.java that aks the user to enter a total of five decimal numbers using showInputDialog boxes. After the five numbers are entered, tha program should used a showInputDialog box to ask the user to do the following, Enter 1 to find the maximum of the five numbers, Enter 2 to find the minimum, or Enter 3 to find the average. The result should be displayed in a showMessageDialog box along with the five original numbers. Use if….else statements and relational operators to fine the minimum and maximum (do not use the Math min or max methods). Use a switch statement to process the different menu items.

i try JOPtion but it got different error

This post has been edited by macosxnerd101: 19 August 2010 - 10:27 AM
Reason for edit:: Title renamed to be more descriptive. Please respect rule #4 of this forum.

Re: Using JOptionPane

Posted 19 August 2010 - 07:42 AM

THE JOPTION BOX DIDN'T WORK

import javax.swing.JOptionPane;
public class NumberOfMonth2
{
public static void main(String[]args)
{
int Year, Month;
String introduction = "This program tell about the day of month base of the year that entered by the user.\n";
JOptionPane.showMessageDialog( null, introduction );
Year =Integer.parseInt(JOptionPane.showInputDialog("Input A Year:"));
Month =Integer.parseInt(JOptionPane.showInputDialog("Input Month"));
if (Year%4>0){ //NOT LEAP YEAR
if (Month==1){
JOptionPane.showMessageDialog(null, "That month is a January!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==2){
JOptionPane.showMessageDialog(null, "That month is a Febuary!");
JOptionPane.showMessageDialog(null, "There's 28 days on that month");}
if (Month==3){
JOptionPane.showMessageDialog(null, "That month is a March!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==4){
JOptionPane.showMessageDialog(null, "That month is a April!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==5){
JOptionPane.showMessageDialog(null, "That month is a May!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==6){
JOptionPane.showMessageDialog(null, "That month is a June!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==7){
JOptionPane.showMessageDialog(null, "That month is a July!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==8){
JOptionPane.showMessageDialog(null, "That month is a August!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==9){
JOptionPane.showMessageDialog(null, "That month is a September!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==10){
JOptionPane.showMessageDialog(null, "That month is a October!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==11){
JOptionPane.showMessageDialog(null, "That month is a November!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==12){
JOptionPane.showMessageDialog(null, "That month is a December!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
}
if (Year%4==0){ //LEAP YEAR
if (Month==1){
JOptionPane.showMessageDialog(null, "That month is a January!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==2){
JOptionPane.showMessageDialog(null, "That month is a Febuary!");
JOptionPane.showMessageDialog(null, "There's 29 days on that month");}
if (Month==3){
JOptionPane.showMessageDialog(null, "That month is a March!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==4){
JOptionPane.showMessageDialog(null, "That month is a April!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==5){
JOptionPane.showMessageDialog(null, "That month is a May!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==6){
JOptionPane.showMessageDialog(null, "That month is a June!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==7){
JOptionPane.showMessageDialog(null, "That month is a July!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==8){
JOptionPane.showMessageDialog(null, "That month is a August!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==9){
JOptionPane.showMessageDialog(null, "That month is a September!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==10){
JOptionPane.showMessageDialog(null, "That month is a October!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
if (Month==11){
JOptionPane.showMessageDialog(null, "That month is a November!");
JOptionPane.showMessageDialog(null, "There's 30 days on that month");}
if (Month==12){
JOptionPane.showMessageDialog(null, "That month is a December!");
JOptionPane.showMessageDialog(null, "There's 31 days on that month");}
}
} // end main
} // end class

macosxnerd101, on 19 August 2010 - 06:25 AM, said:

Show us your code and post your errors. We can't help you fix your code if we can't see it.

can u please check this one the JOption box didn't work only cmd
can u please give me a tips how can i do my 1st question.

This post has been edited by macosxnerd101: 19 August 2010 - 10:26 AM
Reason for edit:: Added code tags. Please use them in the future.

Re: Using JOptionPane

Posted 19 August 2010 - 09:43 AM

[quote name='tissuepaper16' date='19 August 2010 - 07:51 AM' timestamp='1282233096' post='1095249']
i don't know how to make this in JOPtion dialog box because i didn't know what is code for loop
that's all thank you

Then on line 26 replace input.nextDouble(); with the String being parsed into a double.
Take a look at the Double class to see how to parse a String to a double ( Im not going to give you the code I want you to go look at the java doc.) http://download-llnw...ang/Double.html