-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotPol.java
More file actions
147 lines (145 loc) · 5.64 KB
/
Copy pathNotPol.java
File metadata and controls
147 lines (145 loc) · 5.64 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
package colass;
import java.io.IOException;
import java.util.Scanner;
public class NotPol {
public static void main (String args[]) throws IOException{
Scanner sc = new Scanner(System.in);
ColasNenteros CI = new ColasNenteros(5);
int operand =0,num;
int opera = 0;
String ope;
System.out.println("Bienvenido a este programa");
System.out.println("Escribe tu operacion...");
ope=sc.nextLine();
try{
int contn = 0, suma = 0;
if (ope.compareToIgnoreCase("+")==0){
System.out.println("Escribe el operando 1:");
operand = sc.nextInt();
CI.encolar(operand);
suma = operand + suma;
System.out.println("Escribe el operando 2:");
operand = sc.nextInt();
CI.encolar(operand);
suma = operand + suma;
System.out.println("Escribe el operando 3:");
operand = sc.nextInt();
CI.encolar(operand);
suma = operand + suma;
System.out.println("Escribe el operando 4:");
operand = sc.nextInt();
CI.encolar(operand);
suma = operand + suma;
System.out.println("Escribe el operando 5:");
operand = sc.nextInt();
CI.encolar(operand);
suma = operand + suma;
System.out.println();
System.out.println("El resultado es: "+suma);
System.out.print("Notación Polaca: "+"+ ");
for (int i=0; i< 6; i++){
num = CI.sacar();
System.out.print(num+" ");
}
System.out.println();
}
if (ope.compareTo("-") == 0){
int resta = 0;
//System.out.print("resta");
System.out.println("Escribe el operando 1:");
operand = sc.nextInt();
CI.encolar(operand);
resta = operand - resta;
System.out.println("Escribe el operando 2:");
operand = sc.nextInt();
CI.encolar(operand);
resta = resta - operand;
System.out.println("Escribe el operando 3:");
operand = sc.nextInt();
CI.encolar(operand);
resta = resta - operand;
System.out.println("Escribe el operando 4:");
operand = sc.nextInt();
CI.encolar(operand);
resta = resta - operand;
System.out.println("Escribe el operando 5:");
operand = sc.nextInt();
CI.encolar(operand);
resta = resta - operand;
System.out.println();System.out.println("El resultado es: "+resta);
System.out.print("Notación Polaca: "+"* ");
for (int i=0; i< 6; i++){
num = CI.sacar();
System.out.print(num+" ");
}
System.out.println();
}
if (ope.compareTo("*") == 0){
double multi = 1;
System.out.print("mult");
System.out.println("Escribe el operando 1:");
operand = sc.nextInt();
CI.encolar(operand);
multi = operand * multi;
System.out.println("Escribe el operando 2:");
operand = sc.nextInt();
CI.encolar(operand);
multi = multi * operand;
System.out.println("Escribe el operando 3:");
operand = sc.nextInt();
CI.encolar(operand);
multi = multi * operand;
System.out.println("Escribe el operando 4:");
operand = sc.nextInt();
CI.encolar(operand);
multi = multi * operand;
System.out.println("Escribe el operando 5:");
operand = sc.nextInt();
CI.encolar(operand);
multi = multi * operand;
System.out.println();System.out.println("El resultado es: "+multi);
System.out.print("Notación Polaca: "+"* ");
for (int i=0; i< 6; i++){
num = CI.sacar();
System.out.print(num+" ");
}
System.out.println();
}
if (ope.compareTo("/") == 0){
double divi = 1;
System.out.print("div");
System.out.println("Escribe el operando 1:");
operand = sc.nextInt();
CI.encolar(operand);
divi = operand / divi;
System.out.println("Escribe el operando 2:");
operand = sc.nextInt();
CI.encolar(operand);
divi = divi / operand;
System.out.println("Escribe el operando 3:");
operand = sc.nextInt();
CI.encolar(operand);
divi = divi / operand;
System.out.println("Escribe el operando 4:");
operand = sc.nextInt();
CI.encolar(operand);
divi = divi / operand;
System.out.println("Escribe el operando 5:");
operand = sc.nextInt();
CI.encolar(operand);
divi = divi / operand;
System.out.println();System.out.println("El resultado es: "+divi);
System.out.print("Notación Polaca: "+"* ");
for (int i=0; i< 6; i++){
num = CI.sacar();
System.out.print(num+" ");
}
System.out.println();
}
}catch (ExcepcionColaLlena E){
System.out.println(E.getMessage());
}catch(ExcepcionColaVacia Err){
System.out.println(Err.getMessage());
}
}
}