-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMagicDates.java
More file actions
46 lines (36 loc) · 1.41 KB
/
Copy pathMagicDates.java
File metadata and controls
46 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import javax.swing.JOptionPane;
/**@author Lemuel M. Uhuru
* @Date June 5, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 189 Problem 2: Magic Dates
*
* Program that asks the user to enter a month (in numeric form),
* a day, and a two digit year. The program should then determine
* whether the month times the day is equal to the year. If so,
* it should display a message saying the date is magic. Otherwise,
* it should display a message saying the date is not magic.
*/
public class MagicDates {
public static void main(String[] args) {
// Declare 3 variables to hold user input for month, day, and year.
String input1, input2, input3;
// Prompt user for input
input1 = JOptionPane.showInputDialog(null, "Enter a month in numeric form");
input2 = JOptionPane.showInputDialog(null, "Enter a day in numeric form");
input3 = JOptionPane.showInputDialog(null, "Enter a 2 digit year");
// Convert user input from String to Integer
// and store in variables m, d, and y.
int m = Integer.parseInt(input1);
int d = Integer.parseInt(input2);
int y = Integer.parseInt(input3);
// Design decision structure to validate whether or not
// the product of the month and day equals the year.
if (m * d == y){
JOptionPane.showMessageDialog(null, "The date is magic!");
}
else
{
JOptionPane.showMessageDialog(null, "The date is not magic!");
}
}
}