-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOctal.java
261 lines (238 loc) · 8.74 KB
/
Octal.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
261
import java.util.*; // All Utils Library
import java.io.*; // All Input Output Library
import javax.swing.JOptionPane; // JPANEL
class Octal{
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 octal_input; // Input Octal 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 octal_home(){ // Main Menu of Octal Numbers
try{
Index o_anim = new Index();
o_anim.CharAnimation("\n =========================","05");
o_anim.CharAnimation("\n Octal Numbers ","05");
o_anim.CharAnimation("\n =========================","05");
o_anim.CharAnimation("\n\n 1. Octal -> Binary","05");
o_anim.CharAnimation("\n\n 2. Octal -> Decimal","05");
o_anim.CharAnimation("\n\n 3. Octal -> Hexadecimal","05");
o_anim.CharAnimation("\n\n -------------------------","05");
o_anim.CharAnimation("\n 4. MainMenu || 5. About ","05");
o_anim.CharAnimation("\n -------------------------","05");
}catch(Exception e){
System.exit(0);
}
}
public static void switcher(){ // Menu Chooser For Octal Numbers
Index octal_switch = new Index();
switch(getMenu_choice()){ // Get Choice
case 1:
octal_input = null; // Reset Variable
octal_binary();
break;
case 2:
octal_input = null; // Reset Variable
octal_decimal();
break;
case 3:
octal_input = null; // Reset Variable
octal_hexadecimal();
break;
case 4:
octal_switch.mainmenu();
break;
case 5:
octal_switch.aboutprogram();
octal_switch.octalfunction();
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
octal_switch.octalfunction();
}
}
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 inputoctalnum(){ // Input For Octal Numbers
Index io_on = new Index();
datareader();
String username = splitted_text_data[1];
io_on.CharAnimation("\n\n "+username+" > Input Octal Digit : ","02");
try{
octal_input = input.next();
}catch(Exception e){
System.exit(0);
}
}
// Octal Functions
public static void octal_binary(){
Index o_b = new Index();
try{
o_b.clearscreen();
o_b.CharAnimation("\n ===================","05");
o_b.CharAnimation("\n # Octal -> Binary #","05");
o_b.CharAnimation("\n ===================","05");
// Convert Octal to Binary Function Start Here
if(octal_input != null){
}else{
inputoctalnum();
}
String octalNumber = octal_input;
int num = Integer.parseInt(octalNumber, 8);
String binaryNumber = Integer.toBinaryString(num);
// Convert Octal to Binary Function End Here
o_b.CharAnimation("\n -----------------------------------------------","01");
System.out.println("\n Octal("+octalNumber+")"+" = "+"Binary("+binaryNumber+")");
o_b.CharAnimation(" -----------------------------------------------","01");
o_b.CharAnimation("\n -----------------------------------------------","01");
o_b.CharAnimation("\n 1.Convert More || 2.Octal Functions || 0.Exit","01");
o_b.CharAnimation("\n -----------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
o_b.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
octal_input = null;
octal_binary();
break;
case 2:
o_b.octalfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
octal_binary();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
octal_binary();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Octal Digit ! \n Please Try Again..."," Octal Digit Error", JOptionPane.ERROR_MESSAGE);
octal_input = null;
octal_binary();
}
}
public static void octal_decimal(){
Index o_d = new Index();
try{
o_d.clearscreen();
o_d.CharAnimation("\n ====================","05");
o_d.CharAnimation("\n # Octal -> Decimal #","05");
o_d.CharAnimation("\n ====================","05");
// Convert Octal to Decimal Function Start Here
if(octal_input != null){
}else{
inputoctalnum();
}
String octalNumber = octal_input;
int num = Integer.parseInt(octalNumber, 8);
String decimalNumber = Integer.toString(num);
// Convert Octal to Decimal Function End Here
o_d.CharAnimation("\n -----------------------------------------------","01");
System.out.println("\n Octal("+octalNumber+")"+" = "+"Decimal("+decimalNumber+")");
o_d.CharAnimation(" -----------------------------------------------","01");
o_d.CharAnimation("\n -----------------------------------------------","01");
o_d.CharAnimation("\n 1.Convert More || 2.Octal Functions || 0.Exit","01");
o_d.CharAnimation("\n -----------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
o_d.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
octal_input = null;
octal_decimal();
break;
case 2:
o_d.octalfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
octal_decimal();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
octal_decimal();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Octal Digit ! \n Please Try Again..."," Octal Digit Error", JOptionPane.ERROR_MESSAGE);
octal_input = null;
octal_decimal();
}
}
public static void octal_hexadecimal(){
Index o_h = new Index();
try{
o_h.clearscreen();
o_h.CharAnimation("\n ========================","05");
o_h.CharAnimation("\n # Octal -> Hexadecimal #","05");
o_h.CharAnimation("\n ========================","05");
// Convert Octal to Hexadecimal Function Start Here
if(octal_input != null){
}else{
inputoctalnum();
}
String octalNumber = octal_input;
int num = Integer.parseInt(octalNumber, 8);
String hexadecimalNumber = Integer.toHexString(num);
// Convert Octal to Hexadecimal Function End Here
o_h.CharAnimation("\n -----------------------------------------------","01");
System.out.println("\n Octal("+octalNumber+")"+" = "+"Hexadecimal("+hexadecimalNumber+")");
o_h.CharAnimation(" -----------------------------------------------","01");
o_h.CharAnimation("\n -----------------------------------------------","01");
o_h.CharAnimation("\n 1.Convert More || 2.Octal Functions || 0.Exit","01");
o_h.CharAnimation("\n -----------------------------------------------","01");
datareader();
String username = splitted_text_data[1];
o_h.CharAnimation("\n\n "+username+" > Choice : ","02");
convert_again = input.nextInt();
switch(convert_again){
case 1:
octal_input = null;
octal_hexadecimal();
break;
case 2:
o_h.octalfunction();
break;
case 0:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
octal_hexadecimal();
}
}catch(java.util.InputMismatchException e){
JOptionPane.showMessageDialog(null," Invalid Choice ! \n Please Try Again..."," Invalid Choice", JOptionPane.ERROR_MESSAGE);
input.next();
octal_hexadecimal();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null," Invalid Octal Digit ! \n Please Try Again..."," Octal Digit Error", JOptionPane.ERROR_MESSAGE);
octal_input = null;
octal_hexadecimal();
}
}
}