Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Autores : Miguel Angel Rivera - 2059876 - 3743
- Juan Felipe Arango - 2060066 - 3743
- */
- package tallerevaluable1;
- import javax.swing.JOptionPane;
- import java.util.*;
- public class pregunta2 {
- char NxM[][];
- //Stack <Integer> orden = new Stack <Integer>();
- char arregloMinus[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','ñ','o','p','q','r','s','t','u','v','w','x','y','z', ' '};
- char arregloMayus[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','Ñ','O','P','Q','R','S','T','U','V','W','X','Y','Z', ' '};
- public void menuFilasColumnas(){
- int opc;
- do{
- String entrada = JOptionPane.showInputDialog("Elija la distribucion de filas y columnas (su multiplicacion simpre sera 28) \n\n"+
- "1. 28 filas x 1 columna\n"+
- "2. 1 fila x 28 columnas\n"+
- "3. 14 filas x 2 columnas\n"+
- "4. 2 filas x 14 columnas\n"+
- "5. 7 filas x 4 columnas\n"+
- "6. 4 filas x 7 columnas\n");
- opc = Integer.parseInt(entrada);
- switch(opc){
- case 1: NxM = new char[28][1]; opc = 0; break;
- case 2: NxM = new char[1][28]; opc = 0; break;
- case 3: NxM = new char[14][2]; opc = 0; break;
- case 4: NxM = new char[2][14]; opc = 0; break;
- case 5: NxM = new char[7][4]; opc = 0; break;
- case 6: NxM = new char[4][7]; opc = 0; break;
- default: JOptionPane.showMessageDialog(null, "La opcion elegida no es valida");
- }
- }while(opc != 0);
- }
- public void menuMinusMayus(){
- int opc;
- do{
- String entrada = JOptionPane.showInputDialog("Elegir si se desea llenar en minusculas o mayusculas \n\n"+
- "1. Llenar con minusculas \n"+
- "2. Llenar con mayusculas\n");
- opc = Integer.parseInt(entrada);
- switch(opc){
- case 1: minus(); opc = 0; break;
- case 2: ; mayus(); opc = 0; break;
- default: JOptionPane.showMessageDialog(null,"Opcion no valida", "ERROR", 0);
- }
- }while(opc != 0);
- }
- public void minus(){
- int pos;
- int nNums = 28;
- Stack < Integer > orden = new Stack < Integer > ();
- for (int i = 0; i < nNums ; i++) {
- pos = (int) (Math.random() * nNums );
- while (orden.contains(pos)) {
- pos = (int) (Math.random() * nNums );
- }
- orden.push(pos);
- }
- for (int f = 0; f < NxM.length; f++) {
- for (int c = 0; c < NxM[0].length; c++) {
- NxM[f][c] = arregloMinus[orden.pop()];
- }
- }
- }
- public void mayus(){
- int pos;
- int nNums = 28;
- Stack < Integer > orden = new Stack < Integer > ();
- for (int i = 0; i < nNums ; i++) {
- pos = (int) (Math.random() * nNums );
- while (orden.contains(pos)) {
- pos = (int) (Math.random() * nNums );
- }
- orden.push(pos);
- }
- for (int f = 0; f < NxM.length; f++) {
- for (int c = 0; c < NxM[0].length; c++) {
- NxM[f][c] = arregloMayus[orden.pop()];
- }
- }
- }
- public void menuPrincipal(){
- int opc;
- do{
- String entrada = JOptionPane.showInputDialog(" MENU PRINCIPAL \n\n"+
- "1. Elegir el tamaño de la matriz NxM\n"+
- "0. salir");
- opc = Integer.parseInt(entrada);
- switch(opc){
- case 1: menuFilasColumnas(); menuMinusMayus(); imprimir(); break;
- case 0: break;
- default: JOptionPane.showMessageDialog(null, "Opcion invalida", "ERROR", 0);
- }
- }while(opc != 0);
- }
- public void imprimir(){
- String salida = "";
- for (int f = 0; f < NxM.length; f++) {
- for (int c = 0; c < NxM[0].length; c++) {
- salida += NxM[f][c] + " ";
- }
- salida += "\n";
- }
- JOptionPane.showMessageDialog(null,"La matriz es: \n"+ salida);
- }
- //Esto es una opcion de prueba
- public void imprimirConsola(){
- String salida = "";
- for (int f = 0; f < NxM.length; f++) {
- for (int c = 0; c < NxM[0].length; c++) {
- salida += NxM[f][c] + " ";
- }
- salida += "\n";
- }
- System.out.print(salida);
- }
- public static void main(String[] args) {
- pregunta2 obj = new pregunta2();
- obj.menuPrincipal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement