-
Notifications
You must be signed in to change notification settings - Fork 0
/
Binary.java
260 lines (237 loc) · 8.8 KB
/
Binary.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import java.util.*; // All Utils Library
import java.io.*; // All Input Output Library
import javax.swing.JOptionPane; // JPANEL
class Binary{
public static int menu_choice; // Choice for Menu Selection
public static int convert_again; // Convert Again Options Menu Choice
public static Scanner input = new Scanner(System.in); // Scanner Object
public static String filename = "[email protected]"; // Register File
public static String binary_input; // Input binary value
public static String[] splitted_text_data; // Split Text Data and keep into this variable
public int setMenu_choice(int menu_choice) { // Set Menu || Setter
return this.menu_choice = menu_choice;
}
public static int getMenu_choice() { // Get Menu || Getter
return menu_choice;
}
public static void binary_home(){ // Main Menu of Binary Numbers
try{
Index b_anim = new Index();
b_anim.CharAnimation("\n ========================","05");
b_anim.CharAnimation("\n Binary Numbers ","05");
b_anim.CharAnimation("\n ========================","05");
b_anim.CharAnimation("\n\n 1. Binary -> Octal","05");
b_anim.CharAnimation("\n\n 2. Binary -> Decimal","05");
b_anim.CharAnimation("\n\n 3. Binary -> Hexadecimal","05");
b_anim.CharAnimation("\n\n -------------------------","05");
b_anim.CharAnimation("\n 4. MainMenu || 5. About ","05");
b_anim.CharAnimation("\n -------------------------","05");
}catch(Exception e){
System.exit(0);
}
}
public static void switcher(){ // Menu Chooser For Binary Numbers
Index binary_switch = new Index();
switch(getMenu_choice()){ // Get Choice
case 1:
binary_input = null; // Reset Variable
binary_octal();
break;
case 2:
binary_input = null; // Reset Variable
binary_decimal();
break;
case 3:
binary_input = null; // Reset Variable
binary_hexadecimal();
break;
case 4:
binary_switch.mainmenu();
break;
case 5:
binary_switch.aboutprogram();
binary_switch.binaryfunction();
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
binary_switch.binaryfunction();
}
}
public static void datareader(){ // Read Username from file
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader(filename));
while ((line = br.readLine()) != null) {
String delimitators = "([:\\n\\r\\s\\t]+)";
splitted_text_data = line.split(delimitators);
}
}catch(IOException e) {
e.printStackTrace();
}
}
public static void inputbinarynum(){ // Input For Binary Numbers
Index io_bn = new Index();
datareader();
String username = splitted_text_data[1];
io_bn.CharAnimation("\n\n "+username+" > Input Binary Digit : ","02");
try{
binary_input = input.next();
}catch(Exception e){
System.exit(0);
}
}
// Binary Functions
public static void binary_octal(){
Index b_o = new Index();
try{
b_o.clearscreen();
b_o.CharAnimation("\n ===================","05");
b_o.CharAnimation("\n # Binary -> Octal #","05");
b_o.CharAnimation("\n ===================","05");
// Convert Binary to Octal Function Start Here
if(binary_input != null){
}else{
inputbinarynum();
}
String binaryNumber = binary_input;
int num = Integer.parseInt(binary_input, 2);
String octalNumber = Integer.toOctalString(num);
// Convert Binary to Octal Function End Here
b_o.CharAnimation("\n ------------------------------------------------","01");
System.out.println("\n Binary("+binaryNumber+")"+" = "+"Octal("+octalNumber+")");
b_o.CharAnimation(" ------------------------------------------------","01");
b_o.CharAnimation("\n ------------------------------------------------","01");
b_o.CharAnimation("\n 1.Convert More || 2.Binary Functions || 0.Exit","01");
b_o.CharAnimation("\n ------------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
b_o.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
binary_input = null;
binary_octal();
break;
case 2:
b_o.binaryfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
binary_octal();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
binary_octal();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Binary Digit ! \n Please Try Again..."," Binary Digit Error", JOptionPane.ERROR_MESSAGE);
binary_input = null;
binary_octal();
}
}
public static void binary_decimal(){
Index b_d = new Index();
try{
b_d.clearscreen();
b_d.CharAnimation("\n =====================","05");
b_d.CharAnimation("\n # Binary -> Decimal #","05");
b_d.CharAnimation("\n =====================","05");
// Convert Binary to Decimal Function Start Here
if(binary_input != null){
}else{
inputbinarynum();
}
String binaryNumber = binary_input;
int decimalNumber = Integer.parseInt(binaryNumber,2);
// Convert Binary to Decimal Function End Here
b_d.CharAnimation("\n ------------------------------------------------","01");
System.out.println("\n Binary("+binaryNumber+")"+" = "+"Decimal("+decimalNumber+")");
b_d.CharAnimation(" ------------------------------------------------","01");
b_d.CharAnimation("\n ------------------------------------------------","01");
b_d.CharAnimation("\n 1.Convert More || 2.Binary Functions || 0.Exit","01");
b_d.CharAnimation("\n ------------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
b_d.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
binary_input = null;
binary_decimal();
break;
case 2:
b_d.binaryfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
binary_decimal();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
binary_decimal();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Binary Digit ! \n Please Try Again..."," Binary Digit Error", JOptionPane.ERROR_MESSAGE);
binary_input = null;
binary_decimal();
}
}
public static void binary_hexadecimal(){
Index b_h = new Index();
try{
b_h.clearscreen();
b_h.CharAnimation("\n ==========================","05");
b_h.CharAnimation("\n # Binary -> Hexadecimal #","05");
b_h.CharAnimation("\n ==========================","05");
// Convert Binary to Hexadecimal Function Start Here
if(binary_input != null){
}else{
inputbinarynum();
}
String binaryNumber = binary_input;
int i = Integer.parseInt(binary_input,2);
String hexadecimalNumber = Integer.toHexString(i);
// Convert Binary to Hexadecimal Function End Here
b_h.CharAnimation("\n ------------------------------------------------","01");
System.out.println("\n Binary("+binaryNumber+")"+" = "+"HexadDecimal("+hexadecimalNumber+")");
b_h.CharAnimation(" ------------------------------------------------","01");
b_h.CharAnimation("\n ------------------------------------------------","01");
b_h.CharAnimation("\n 1.Convert More || 2.Binary Functions || 0.Exit","01");
b_h.CharAnimation("\n ------------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
b_h.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
binary_input = null;
binary_hexadecimal();
break;
case 2:
b_h.binaryfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
binary_hexadecimal();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
binary_hexadecimal();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Binary Digit ! \n Please Try Again..."," Binary Digit Error", JOptionPane.ERROR_MESSAGE);
binary_input = null;
binary_hexadecimal();
}
}
}