Question: Please create a JAVA program by following all these directions: Using a GUI (hint: JOptionPane) write a program that prompts the user to input any

Please create a JAVA program by following all these directions:

Using a GUI (hint: JOptionPane) write a program that prompts the user to input any 3 decimal numbers. The program should then display (hint: JOptionPane.showMessageDialog) the sum and average of the 3 numbers.

Example of how to start the program:

// Chapter 2 GUI

import javax.swing.JOptionPane; class ch2sample { public static void main(String[] args) { String num1String,num2String,num3String; double num1,num2,num3,sum,avg; num1String = JOptionPane.showInputDialog(null,"Enter the first decimal number"); // finish the program

}

}

The JOptionPane class is used to provide a dialog box. You will use it in this program for input and output. When you use the showInputDialog the input information gets returned as a string. If you want the information as a different variable type like double (and we do) then you must convert it or parse it. Parse Example: num1 = Double.parseDouble(num1String); Now num1 is a decicmal number and it's ready to be used in a math calculation.

Output Example: JOptionPane.showMessageDialog(null, "Hello " + variable + " " + "How are you?"); Assume the variable is a name like Mr. O. this dialog box would display 2 lines; Hello Mr. O on the first line and How are you? on the second line. The plus sign means combine text with a variable and omitting the plus sign creates syntax errors.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!