-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convertor.java
82 lines (76 loc) · 2.03 KB
/
Convertor.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
82
import javax.swing.JOptionPane;
/**
* This class is the parent of all convertors and contains the value to convert
*
* @version 1.0.0
* @since 1.0.0
* @see TemperatureConvertor
* @see CurrencyConvertor
*
* @autor JuanObandoDev
*/
public abstract class Convertor {
private int valueToConvert;
private String origin;
/**
* This constructor calls the method valueToConvert() and sets the value to
* convert
*/
public Convertor() {
this.valueToConvert = valueToConvert();
this.origin = "";
}
/**
* This method returns the value to convert
*
* @return this.valueToConvert
*/
public int getValueToConvert() {
return this.valueToConvert;
}
/**
* This method returns the origin of the convertor
*
* @return this.origin
*/
public String getOrigin() {
return this.origin;
}
/**
* This method asks the user for the value to convert and returns it
*
* @return Integer.parseInt(value) || 0 || valueToConvert()
*/
public int valueToConvert() {
try {
String value = JOptionPane.showInputDialog(
null,
"Enter the value to convert");
if (value != null) {
return Integer.parseInt(value);
}
JOptionPane.showMessageDialog(
null,
"Thanks for using the convertor");
System.exit(0);
return 0;
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
null,
"Please enter a valid number");
return valueToConvert();
}
}
/**
* This method separates the selection of the user and returns the value to
* convert
*
* @param selected
* @return parts[2]
*/
public String separateSelection(String selected) {
String[] parts = selected.split(" ");
this.origin = parts[0];
return parts[2];
}
}