Author: GUILLERMO LONDOÑO Y FABIAN CANO 624041 Y 624020
Desc: ES UN CUBO MAGICO QUE SUMA SUS FILAS COLUMNAS Y DIAGONAL PRINCIPAL Y TRANSVERSAL.
Para la materia esquemas y técnicas jornada nocturna con el profesor Luis Alejandro Bernal
- Archivo
- Escritura.java
1 package pkgElCubo;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import java.awt.event.*;
6
7 public class Escritura {
8
9 public static void datoCadena(String dato) {
10 datoCadena(dato,'N');
11 }
12
13 public static void datoCadena(String dato, char NuevaLinea) {
14 try{
15 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
16 System.out.println(dato);
17 else
18 System.out.print(dato);
19 }catch(Exception e) {
20 System.err.println("Error: " + e.getMessage());
21 }
22 }
23
24 public static void datoShort(Short dato) {
25 datoShort(dato,'N');
26 }
27
28 public static void datoShort(Short dato, char NuevaLinea) {
29 try{
30 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
31 System.out.println(dato);
32 else
33 System.out.print(dato);
34 }catch(Exception e){
35 System.err.println("Error: " + e.getMessage());
36 }
37 }
38
39 public static void datoInt(int dato) {
40 datoInt(dato,'N');
41 }
42
43 public static void datoInt(int dato, char NuevaLinea) {
44 try{
45 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
46 System.out.println(dato);
47 else
48 System.out.print(dato);
49 }catch(Exception e){
50 System.err.println("Error: " + e.getMessage());
51 }
52 }
53
54 public static void datoLong(Long dato) {
55 datoLong(dato,'N');
56 }
57
58 public static void datoLong(Long dato, char NuevaLinea) {
59 try{
60 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
61 System.out.println(dato);
62 else
63 System.out.print(dato);
64 }catch(Exception e){
65 System.err.println("Error: " + e.getMessage());
66 }
67 }
68
69 public static void datoFloat(Float dato){
70 datoFloat(dato,'N');
71 }
72
73 public static void datoFloat(Float dato, char NuevaLinea) {
74 try{
75 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
76 System.out.println(dato);
77 else
78 System.out.print(dato);
79 }catch(Exception e){
80 System.err.println("Error: " + e.getMessage());
81 }
82 }
83
84 public static void datoDouble(Double dato) {
85 datoDouble(dato,'N');
86 }
87
88 public static void datoDouble(Double dato, char NuevaLinea) {
89 try{
90 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
91 System.out.println(dato);
92 else
93 System.out.print(dato);
94 }catch(Exception e){
95 System.err.println("Error: " + e.getMessage());
96 }
97 }
98
99 public static void datoBooleano(Boolean dato) {
100 datoBooleano(dato,'N');
101 }
102
103 public static void datoBooleano(Boolean dato, char NuevaLinea) {
104 try{
105 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
106 System.out.println(dato);
107 else
108 System.out.print(dato);
109 }catch(Exception e){
110 System.err.println("Error: " + e.getMessage());
111 }
112 }
113
114 public static void datoCaracter(char dato) {
115 datoCaracter(dato,'N');
116 }
117
118 public static void datoCaracter(char dato, char NuevaLinea) {
119 try{
120 if ((NuevaLinea == 'S')||(NuevaLinea == 's'))
121 System.out.println(dato);
122 else
123 System.out.print(dato);
124 }catch(Exception e){
125 System.err.println("Error: " + e.getMessage());
126 }
127 }
128 }
- Archivo
- Lectura.java
1 package pkgElCubo;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import java.awt.event.*;
6 import java.io.BufferedReader;
7 import java.io.IOException;
8 import java.io.InputStreamReader;
9
10 public class Lectura {
11
12 public static String datoCadena() {
13 String sdatoCadena =" ";
14 try {
15 //se define un flujo de caracteres de entrada: flujoE
16 InputStreamReader isr= new InputStreamReader(System.in);
17 BufferedReader flujoE = new BufferedReader(isr);
18
19 //Leer la entrada finaliza al pulsar Enter
20 sdatoCadena = flujoE.readLine();
21 }catch(IOException e){
22 System.err.println("Error: " + e.getMessage());
23 }
24
25 return sdatoCadena;
26 //devuelve el datoCadena tecleado
27 }
28
29 public static short datoShort() {
30 try{
31 return Short.parseShort(datoCadena());
32 }catch(NumberFormatException e){
33 return Short.MIN_VALUE;
34 // valor más pequeño
35 }
36 }
37
38 public static int datoInt() {
39 try{
40 return Integer.parseInt(datoCadena());
41 }catch(NumberFormatException e) {
42 return Integer.MIN_VALUE;
43 // valor más pequeño
44 }
45 }
46
47 public static long datoLong() {
48 try{
49 return Long.parseLong(datoCadena());
50 }catch(NumberFormatException e) {
51 return Long.MIN_VALUE;
52 // valor más pequeño
53 }
54 }
55
56 public static float datoFloat() {
57 try{
58 Float f = new Float(datoCadena()); return f.floatValue();
59 }catch(NumberFormatException e) {
60 return Float.NaN;
61 //no es un valor float
62 }
63 }
64
65 public static double datoDouble() {
66 try{
67 Double d = new Double(datoCadena());
68 return d.doubleValue();
69 }catch(NumberFormatException e){
70 return Double.NaN;//no es un valor double
71 }
72 }
73
74 public static boolean datoBooleano() {
75 try{
76 Boolean d = new Boolean(datoCadena());
77 return d.booleanValue();
78 }catch(Exception e) {
79 return false;
80 }
81 }
82
83 public static char datoCaracter() {
84 try {
85 String Captura;
86 char d;
87 Captura = datoCadena();
88 d = Captura.charAt(0);
89 return d;
90 }catch(Exception e) {
91 return ' ';
92 }
93 }
94 }
- Archivo
- Cubo.java
1 package pkgElCubo;
2
3 public class Cubo {
4 public static void main(String[] args) {
5 int [][] mat1;
6 mat1= new int [5][5];
7 int [] vec1;
8 vec1= new int [5];
9 int [] vec2;
10 vec2= new int [5];
11 int [] vec3;
12 vec3= new int [5];
13 int [] vec4;
14 vec4= new int [5];
15 int opc=1;
16
17 while (opc!=0){
18 int fila=0;
19 int col=0;
20 int pos=0;
21 int fvec=0;
22 int cvec=0;
23 int num=0;
24 int aux0=0;
25 int aux1=0;
26 int aux2=25;
27 int aux4=0;
28 int acum=0;
29 float aux3=0;
30 float res=0;
31 fila=capturaFila();
32 col=capturaCol();
33 num=capturaNum();
34 System.out.println(" ");
35
36 for(aux0=0;aux0<26;aux0++){
37 mat1[fila][col]=num;
38 aux1=num;
39
40 if((aux1>=2)&&(aux1<=25)){
41 res=calcularRes(aux1, aux2);
42 aux3=res%5;
43
44 if(aux3==0){
45 col=col+2;
46
47 if(col==6){
48 col=1;
49 }
50 if(col==5){
51 col=0;
52 }
53 }
54
55 if(aux3!=0){
56 fila=fila+2;
57
58 if(fila==6){
59 fila=1;
60 }
61 if(fila==5){
62 fila=0;
63 }
64
65 col=col+1;
66 if(col==5){
67 col=0;
68 }
69 }
70 }
71
72 if(num==1){
73 fila=fila+2;
74 if(fila==6){
75 fila=1;
76 }
77
78 if(fila==5){
79 fila=0;
80 }
81
82 col=col+1;
83 if(col==5){
84 col=0;
85 }
86 }
87
88 num=num+1;
89 if(num>25){
90 num=1;
91 }
92 }
93
94 for(fila=0;fila<5;fila++){
95 for(col=0;col<5;col++){
96 System.out.print(" "+mat1[fila][col]);
97 if(col==4){
98 System.out.println();
99 }
100 }
101 }
102
103 System.out.println(" ");
104 fvec=capturaFvec();
105
106 for(fila=fvec;fila==fvec;fila++){
107 for(col=0;col<5;col++){
108 vec1[pos]=mat1[fila][col];
109 pos=pos+1;
110 }
111 break;
112 }
113
114 System.out.println(" ");
115 System.out.print("la fila "+fvec+" es ");
116
117 for(pos=0;pos<5;pos++){
118 acum=acum+vec1[pos];
119 System.out.print(" "+vec1[pos]);
120 }
121
122 System.out.print(" Suma total de la fila = "+acum);
123 System.out.println(" ");
124 System.out.println(" ");
125 cvec=capturaCvec();
126 pos=0;
127
128 for(fila=0;fila<5;fila++){
129 for(col=cvec;col==cvec;col++){
130 vec2[pos]=mat1[fila][col];
131 pos=pos+1;
132 }
133 }
134
135 System.out.println(" ");
136 System.out.print("la columna "+cvec+" es ");
137 acum=0;
138
139 for(pos=0;pos<5;pos++){
140 acum=acum+vec2[pos];
141 System.out.print(" "+vec2[pos]);
142 }
143
144 System.out.print(" Suma total de la columna = "+acum);
145 System.out.println(" ");
146 pos=0;
147 acum=0;
148
149 for(fila=0;fila<5;fila++){
150 for(col=0;col<5;col++){
151 if(fila==col){
152 vec3[pos]=mat1[fila][col];
153 pos=pos+1;
154 }
155 }
156 }
157
158 System.out.println(" ");
159 System.out.print("la diagonal es ");
160
161 for(pos=0;pos<5;pos++){
162 acum=acum+vec3[pos];
163 System.out.print(" "+vec3[pos]);
164 }
165
166 System.out.print(" Suma total de la diagonal = "+acum);
167 System.out.println(" ");
168 pos=0;
169 acum=0;
170
171 for(fila=0;fila<5;fila++){
172 for(col=0;col<5;col++){
173 aux4=fila+col;
174 if(aux4==4){
175 vec4[pos]=mat1[fila][col];
176 pos=pos+1;
177 }
178 }
179 }
180
181 System.out.println(" ");
182 System.out.print("la transversal es ");
183
184 for(pos=0;pos<5;pos++){
185 acum=acum+vec4[pos];
186 System.out.print(" "+vec4[pos]);
187 }
188
189 System.out.print(" Suma total de la tranversal = "+acum);
190 System.out.println(" ");
191 System.out.println(" ");
192 System.out.print("Desea salir digite->0 desea continuar digite cualquier tecla :");
193 opc=Lectura.datoInt();
194 }
195 }
196
197 public static int capturaFila(){
198 int fi=0;
199 System.out.print("Digite la fila entre 0 y 4 donde desea colocar el numero :");
200 fi=Lectura.datoInt();
201 return fi;
202 }
203
204 public static int capturaCol(){
205 int co=0;
206 System.out.print("Digite la columna entre 0 y 4 donde desea colocar el numero :");
207 co=Lectura.datoInt();
208 return co;
209 }
210
211 public static int capturaNum(){
212 int nu=0;
213 System.out.print("Digite un numero entre 1 y 25 con el que desea inicializar :");
214 nu=Lectura.datoInt();
215 return nu;
216 }
217
218 public static float calcularRes(int aux1, int aux2){
219 float rs=0;
220 rs=aux2%aux1;
221 return rs;
222 }
223
224 public static int capturaFvec(){
225 int fi=0;
226 System.out.print("Digite fila entre 0 y 4 a verificar :");
227 fi=Lectura.datoInt();
228 return fi;
229 }
230
231 public static int capturaCvec(){
232 int co=0;
233 System.out.print("Digite columna entre 0 y 4 a verificar :");
234 co=Lectura.datoInt();
235 return co;
236 }
237 }
