-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataConverter.java
More file actions
195 lines (141 loc) · 7.11 KB
/
Copy pathDataConverter.java
File metadata and controls
195 lines (141 loc) · 7.11 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package oopproject1;
import javax.swing.JOptionPane;
/*
@Owner: Md. Shazadur Rahman
Id. No: 1932020013
*/
public class DataConverter {
{
String[] options = {"Byte to KB", "Byte to MB", "Byte to GB", "Byte to TB", "KB to Byte", "KB to MB", "KB to GB", "KB to TB", "MB to Byte", "MB to KB", "MB to GB", "MB to TB", "GB to Byte", "GB to KB", "GB to MB", "GB to TB"};
int x = JOptionPane.showOptionDialog(null, "Your choice", "Click a button",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (x == 0){
//bytes to Kilobyte
String bytes1 = JOptionPane.showInputDialog(null, "Enter the bytes: ", "bytes to Kilobyte", JOptionPane.PLAIN_MESSAGE);
double bytes = Double.parseDouble(bytes1);
double KB = bytes / 1024;
bytes1 = Double.toString(KB);
JOptionPane.showMessageDialog(null, "The KB is: " + bytes1);
}
else if (x == 1) {
//bytes to Megabyte
String bytes1 = JOptionPane.showInputDialog(null, "Enter the bytes: ", "bytes to Megabyte", JOptionPane.PLAIN_MESSAGE);
double bytes = Double.parseDouble(bytes1);
double MB = bytes / 1048576;
bytes1 = Double.toString(MB);
JOptionPane.showMessageDialog(null, "The MB is: " + bytes1);
}
else if (x == 2) {
//bytes to Gigabyte
String bytes1 = JOptionPane.showInputDialog(null, "Enter the bytes: ", "bytes to Gigabyte", JOptionPane.PLAIN_MESSAGE);
double bytes = Double.parseDouble(bytes1);
double GB = bytes / 1073741824;
bytes1 = Double.toString(GB);
JOptionPane.showMessageDialog(null, "The GB is: " + bytes1);
}
else if (x == 3) {
//bytes to Terabyte
String bytes1 = JOptionPane.showInputDialog(null, "Enter the bytes: ", "bytes to Terabyte", JOptionPane.PLAIN_MESSAGE);
double bytes = Double.parseDouble(bytes1);
double TB = bytes / 109951162;
bytes1 = Double.toString(TB);
JOptionPane.showMessageDialog(null, "The TB is: " + bytes1);
}
else if (x == 4) {
//Kilobyte to bytes
String Kilobyte = JOptionPane.showInputDialog(null, "Enter the KB: ", "Kilobyte to bytes", JOptionPane.PLAIN_MESSAGE);
double KB = Double.parseDouble(Kilobyte);
double bytes = KB * 1024;
Kilobyte = Double.toString(bytes);
JOptionPane.showMessageDialog(null, "The bytes is: " + Kilobyte);
}
else if (x == 5) {
//Kilobyte to Megabyte
String Kilobyte = JOptionPane.showInputDialog(null, "Enter the KB: ", "Kilobyte to Megabyte", JOptionPane.PLAIN_MESSAGE);
double KB = Double.parseDouble(Kilobyte);
double MB = (KB * 1024) / 1048576;
Kilobyte = Double.toString(MB);
JOptionPane.showMessageDialog(null, "The MB is: " + Kilobyte);
}
else if (x == 6) {
//Kilobyte to Gigabyte
String Kilobyte = JOptionPane.showInputDialog(null, "Enter the KB: ", "Kilobyte to Gigabyte", JOptionPane.PLAIN_MESSAGE);
double KB = Double.parseDouble(Kilobyte);
double GB = KB / 1048576;
Kilobyte = Double.toString(GB);
JOptionPane.showMessageDialog(null, "The GB is: " + Kilobyte);
}
else if (x == 7) {
//Kilobyte to Terabyte
String Kilobyte = JOptionPane.showInputDialog(null, "Enter the KB: ", "Kilobyte to Terabyte", JOptionPane.PLAIN_MESSAGE);
double KB = Double.parseDouble(Kilobyte);
double TB = KB / 1.07374182;
Kilobyte = Double.toString(TB);
JOptionPane.showMessageDialog(null, "The TB is: " + Kilobyte);
}
else if (x == 8) {
//Megabyte to byte
String Megabyte = JOptionPane.showInputDialog(null, "Enter the MB: ", "Megabyte to byte", JOptionPane.PLAIN_MESSAGE);
Double MB = Double.parseDouble(Megabyte);
Double bytes = MB * 1048576;
Megabyte = Double.toString(bytes);
JOptionPane.showMessageDialog(null, "The byte is: " + Megabyte);
}
else if (x == 9) {
//Megabyte to Kilobyte
String Megabyte = JOptionPane.showInputDialog(null, "Enter the MB: ", "Megabyte to Kilobyte", JOptionPane.PLAIN_MESSAGE);
double MB = Double.parseDouble(Megabyte);
double KB = MB * 1024;
Megabyte = Double.toString(KB);
JOptionPane.showMessageDialog(null, "The KB is: " + Megabyte);
}
else if (x == 10) {
//Megabyte to Gigabyte
String Megabyte = JOptionPane.showInputDialog(null, "Enter the MB: ", "Megabyte to Gigabyte", JOptionPane.PLAIN_MESSAGE);
double MB = Double.parseDouble(Megabyte);
double GB = MB / 1024;
Megabyte = Double.toString(GB);
JOptionPane.showMessageDialog(null, "The GB is: " + Megabyte);
}
else if (x == 11) {
//Megabyte to Terabyte
String Megabyte = JOptionPane.showInputDialog(null, "Enter the MB: ", "Megabyte to Terabyte", JOptionPane.PLAIN_MESSAGE);
double MB = Double.parseDouble(Megabyte);
double TB = MB / 1048576;
Megabyte = Double.toString(TB);
JOptionPane.showMessageDialog(null, "The TB is: " + Megabyte);
}
else if (x == 12) {
//Gigabyte to byte
String Gigabyte = JOptionPane.showInputDialog(null, "Enter the GB: ", "Gigabyte to byte", JOptionPane.PLAIN_MESSAGE);
double GB = Double.parseDouble(Gigabyte);
double bytes = GB * 1073741824;
Gigabyte = Double.toString(bytes);
JOptionPane.showMessageDialog(null, "The byte is: " + Gigabyte);
}
else if (x == 13) {
//Gigabyte to Kilobyte
String Gigabyte = JOptionPane.showInputDialog(null, "Enter the GB: ", "Gigabyte to Kilobyte", JOptionPane.PLAIN_MESSAGE);
double GB = Double.parseDouble(Gigabyte);
double KB = GB * 1048576;
Gigabyte = Double.toString(KB);
JOptionPane.showMessageDialog(null, "The KB is: " + Gigabyte);
}
else if (x == 14) {
//Gigabyte to Megabyte
String Gigabyte = JOptionPane.showInputDialog(null, "Enter the GB: ", "Gigabyte to Megabyte", JOptionPane.PLAIN_MESSAGE);
double GB = Double.parseDouble(Gigabyte);
double MB = GB * 1024;
Gigabyte = Double.toString(MB);
JOptionPane.showMessageDialog(null, "The MB is: " + Gigabyte);
}
else {
//Gigabyte to Terabyte
String Gigabyte = JOptionPane.showInputDialog(null, "Enter the GB: ", "Gigabyte to Terabyte", JOptionPane.PLAIN_MESSAGE);
Double GB = Double.parseDouble(Gigabyte);
Double TB = GB / 1024;
Gigabyte = Double.toString(TB);
JOptionPane.showMessageDialog(null, "The TB is: " + Gigabyte);
}
}
}