Using JOptionPane

i cant make a code about

Page 1 of 1

9 Replies - 4634 Views - Last Post: 19 August 2010 - 10:28 AM Rate Topic: -----

#1 tissuepaper16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-August 10

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.


Is This A Good Question/Topic? 0
  • +

Replies To: Using JOptionPane

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: Using JOptionPane

Posted 19 August 2010 - 07:25 AM

Show us your code and post your errors. We can't help you fix your code if we can't see it. :)
Was This Post Helpful? 0
  • +
  • -

#3 tissuepaper16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-August 10

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


View Postmacosxnerd101, 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.

Was This Post Helpful? 0
  • +
  • -

#4 tissuepaper16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-August 10

Re: Using JOptionPane

Posted 19 August 2010 - 08:51 AM

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

import java.util.*;

public class MaxMinAvg {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);


	
      
        double maxnumber = Double.MIN_VALUE;     
        double minNumber = Double.MAX_VALUE; 



        int    count       = 0;              
        double totalNumber = 0;              

     
        System.out.println("Enter five number.  Write DONE if u are entered 5 DIGIT");
        while (input.hasNextDouble()) { 

            double number = input.nextDouble();
            

            if (number > maxnumber) {
                maxnumber = number;
            }
            if (number < minNumber) {
                minNumber = number;
            }

           
            count++;                 
            totalNumber += number;   
        }


        if (count > 0) {
            //... Display statistics
            double average = totalNumber / count;
            System.out.println("Number of values = " + count);
            System.out.println("Maximum = "  + maxnumber);
            System.out.println("Minimum = "  + minNumber);
            System.out.println("Average = "  + average);
        } else {
            System.out.println("Error: You entered no data!");
        }
    }
}


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

Was This Post Helpful? 0
  • +
  • -

#5 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Using JOptionPane

Posted 19 August 2010 - 09:05 AM

for starters, could you please edit your post and put your code within the :code: tags

This post has been edited by Luckless: 19 August 2010 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#6 tissuepaper16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-August 10

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


import java.util.*;

public class MaxMinAvg {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);




double maxnumber = Double.MIN_VALUE;
double minNumber = Double.MAX_VALUE;



int count = 0;
double totalNumber = 0;


System.out.println("Enter five number. Write DONE if u are entered 5 DIGIT");
while (input.hasNextDouble()) {

double number = input.nextDouble();


if (number > maxnumber) {
maxnumber = number;
}
if (number < minNumber) {
minNumber = number;
}


count++;
totalNumber += number;
}


if (count > 0) {
//... Display statistics
double average = totalNumber / count;
System.out.println("Number of values = " + count);
System.out.println("Maximum = " + maxnumber);
System.out.println("Minimum = " + minNumber);
System.out.println("Average = " + average);
} else {
System.out.println("Error: You entered no data!");
}
}
} 


View PostLuckless, on 19 August 2010 - 08:05 AM, said:

for starters, could you please edit your post and put your code within the :code: tags



import java.util.*;

public class MaxMinAvg {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);




double maxnumber = Double.MIN_VALUE;
double minNumber = Double.MAX_VALUE;



int count = 0;
double totalNumber = 0;


System.out.println("Enter five number. Write DONE if u are entered 5 DIGIT");
while (input.hasNextDouble()) {

double number = input.nextDouble();


if (number > maxnumber) {
maxnumber = number;
}
if (number < minNumber) {
minNumber = number;
}


count++;
totalNumber += number;
}


if (count > 0) {
//... Display statistics
double average = totalNumber / count;
System.out.println("Number of values = " + count);
System.out.println("Maximum = " + maxnumber);
System.out.println("Minimum = " + minNumber);
System.out.println("Average = " + average);
} else {
System.out.println("Error: You entered no data!");
}
}
} 

Was This Post Helpful? 0
  • +
  • -

#7 tissuepaper16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-August 10

Re: Using JOptionPane

Posted 19 August 2010 - 09:47 AM

hahaha check dis out very funny run this program to your cmd i supose that any one can help me i want it to be JOprtion the part of while loop i dont know how is it...


import javax.swing.JOptionPane;
import java.util.*;
public class RJ2 {
	
	    public static void main(String[] args) {

		  Scanner input = new Scanner(System.in);


        double maxnumber = Double.MIN_VALUE;     
        double minNumber = Double.MAX_VALUE; 

        int    count       = 0;              
        double totalNumber = 0;   


	String  introduction = "Enter five number.  Write DONE if u are entered 5 DIGIT.\n";
	String  outputMessage;



    	  JOptionPane.showMessageDialog( null, introduction );
	
		while (input.hasNextDouble()){ 

		double number  = input.nextDouble(); // <---- dis part i don't know how it will make JOptiondialog
            

            if (number > maxnumber) {
                maxnumber = number;
            }
            if (number < minNumber) {
                minNumber = number;
		}
		
	

	            count++;                 
            totalNumber += number;  
	}

		double average = totalNumber / count;


		outputMessage = "Number of values = " + count + "\n\n"
			+ "Maximum = "  + maxnumber + "\n\n"
			+ "Minimum = "  + minNumber + "\n\n"
			+ "Average = "  + average + "\n\n"
			 + "End of program";


      JOptionPane.showMessageDialog( null, outputMessage );

      System.exit(0); 

   } 
} 

		


Was This Post Helpful? 0
  • +
  • -

#8 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Using JOptionPane

Posted 19 August 2010 - 10:08 AM

Ok What?!
Ok it seems like you want to show a Input dialog in the loop?
Well you could use JOptionPane.showInputDialog like so before line 26:

String inputValue = JOptionPane.showInputDialog("Please input a value");

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

This post has been edited by H3R3T1C: 19 August 2010 - 10:09 AM

Was This Post Helpful? 0
  • +
  • -

#9 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Using JOptionPane

Posted 19 August 2010 - 10:09 AM

You should use
JOptionPane.showInputDialog



inside of the loop.
why do you think some one is going to enter a number more big than 1.7976931348623157E308 ? because that's the number for Double.MAX_VALUE.
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: Using JOptionPane

Posted 19 August 2010 - 10:28 AM

Duplicate topics merged. Please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1