Explanation of Solution
// Import the JOptionPane package to display dialog boxes
import javax.swing.JOptionPane;
// Class declaration
public class CheckPoint {
// Main function
public static void main(String[] args) {
// Declare the required variables
String s;
int age;
/* Display the dialog box to prompt the user to enter age */
s=JOptionPane.showInputDialog("Enter your age");
// Convert the string variable to int value
age = Integer.parseInt(s);
// Display the age in the message box
JOptionPane.showMessageDialog(null, "The age is "+s);
}
}
Dialog box:
A small graphical window, which is used to display a message to the user or to request input from the user, is called as dialog box. In Java, the dialog boxes can be displayed quickly using JOptionPane class.
This class has to be imported in any program before using it, because it not available automatically. The statement which is used to find the JOptionPane class and makes it available for the program is,
import javax...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
MyLab Programming with Pearson eText -- Access Card -- for Starting Out with Java: Early Objects (Myprogramminglab)
- Given a variable named count that contains an integer value, write a statement that displays the value of count .arrow_forwardWrite a line of code that asks the user to enter their name and stores their answer in a variable called name.arrow_forwardInput a value for the variable y so that the variable x becomes 4 after the code executes. favorite_numbers = y favorite_numbers.remove(-1) x = len(favorite_numbers)arrow_forward
- The following code intends to input a user’s first name, last name, and age.However, it has an error. Fix the code.string fullName;int age;cout << "Enter your first and last name." << endl;cin >> fullName;cout << "Enter your age." << endl;cin >> age;cout << "You are " << age << " years old, " << fullName << endl;arrow_forwardi need to display multiples of what the user entersarrow_forwardCopy the code provided and paste the code into the code window. The following code reads in a value for variable numApples using cin >> and outputs the value of numApples, followed by " apples" using cout <<. cin >> numApples; cout << numApples << " apples" << endl; #include <iostream>using namespace std; int main() { int numApples; // Creates an integer variable named numApples /* Your code goes here */ return 0;}arrow_forward
- Integer variable numYards is read from input. Type cast numYards to a double. Ex: If the input is 26, then the output is: 26.00 #include <iostream>#include <iomanip>using namespace std; int main() { int numYards; cin >> numYards; cout << fixed << setprecision(2) << /* Your code goes here */ << endl; return 0;}arrow_forwardc## please Write a Console Application that reads two integers, determines whether the first is a multiple of the second and displays the result. [Hint: Use the remainder operator.]arrow_forwardInteger variable numMinutes is read from input. Type cast numMinutes to a double. Ex: If the input is 90, then the output is: 90.00 #include <iostream>#include <iomanip>using namespace std; int main() { int numMinutes; cin >> numMinutes; cout << fixed << setprecision(2) << /* Your code goes here */ << endl; return 0;}arrow_forward
- Find errors in the following lines of code assuming included header files. Write correct form with line number. int main() { Int a=4.5 Char ch=’a’ Int a++; Cout<<”the value of a=’; Cout>>a; For( ; a<=5; ) Cout<<a; }arrow_forwardCreate a variable called c, assign a +b to it, and display the result. Assume a is initialized with value of 5 and b with value of 10.arrow_forwardGiven the following variable declaration, choose the option that describes them $num1='18'; $num2=18; a. Variable $num1 is incorrect while Variable $num2 is correct. b. Both the variables have the same data type. c. Variable $num1 has a string data type while variable $num2 is an integer. d. Both the variables are incorrect.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,