-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
81 lines (77 loc) · 2.27 KB
/
Main.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import javax.swing.JOptionPane;
/**
* This class init the program and contains the main method
*
* @version 1.0.0
* @since 1.0.0
* @see TemperatureConvertor
* @see CurrencyConvertor
*
* @autor JuanObandoDev
*/
public class Main {
/**
* This array contains the options of convertors
*/
private static final String[] OPTIONS = {
"Temperature convertor",
"Currency convertor"
};
/**
* This method is the main method and init the program
*
* @param args
*/
public static void main(String[] args) {
int option = 0;
try {
do {
String selected = mainMenu();
switch (selected) {
case "Temperature convertor":
TemperatureConvertor temperatureConvertor = new TemperatureConvertor();
temperatureConvertor.showResult();
break;
case "Currency convertor":
CurrencyConvertor currencyConvertor = new CurrencyConvertor();
currencyConvertor.showResult();
break;
}
option = continueOrNot();
} while (option != 1);
} catch (NullPointerException e) {
// Nothing here because the user clicked the cancel button
} finally {
JOptionPane.showMessageDialog(
null,
"Thanks for using the convertor");
}
}
/**
* This method shows the main menu
*
* @return (String) JOptionPane.showInputDialog
*/
public static String mainMenu() {
return (String) JOptionPane.showInputDialog(
null,
"Select a convertor",
"Convertor",
JOptionPane.INFORMATION_MESSAGE,
null,
OPTIONS,
"None");
}
/**
* This method asks the user if he wants to continue
*
* @return JOptionPane.showConfirmDialog
*/
public static int continueOrNot() {
return JOptionPane.showConfirmDialog(
null,
"Do you want to continue?",
"Continue",
JOptionPane.YES_NO_OPTION);
}
}