EJERCICIO - murga rivera jeery.docx
-
Upload
jerry-murga-rivera -
Category
Documents
-
view
2 -
download
0
Transcript of EJERCICIO - murga rivera jeery.docx
MURGA RIVERA JEERY - 0201213054
EJERCICIO.Escribir un programa que llene una matriz de N por N de valores aleatorios reales. A continuación el programa debe imprimirla por pantalla la suma de las filas y las columnas o algunas de ellas.
package matrizn;//IMPORTANDO LAS CLASES Y SUBCLASES NECESARIASimport javax.swing.*;import java.util.Random;
public class NXN extends javax.swing.JFrame {// LLAMANDO : DefaultListModel private DefaultListModel modelo1=new DefaultListModel(); private DefaultListModel modelo2=new DefaultListModel(); public NXN() {//DECLARANDO LAS LISTAS. initComponents(); jList1.setModel(modelo1); jList2.setModel(modelo2); }
GENERAR VALORES - jButton6
jTextField1
JCheckBox3jCheckBox1
jTextField1
JCheckBox2
JButton5 JButton4
jButton6
jList2 jList1
MURGA RIVERA JEERY - 0201213054
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { //Escribir un programa que llene una matriz de N por N de valores aleatorios reales. //A continuación el programa debe imprimirla por pantalla la suma de las filas y las //columnas o algunas de ellas. Random numerosAleatorios = new Random(); //DECLARANDO LAS VARIABLES NECESARIAS: f = suma de filas, c=suma de columnas, fc= //suma de filas y columnas, n= longitud de la matriz “nxn”. double f=0,c=0,fc=0; String valores=""; int n=Integer.parseInt(jTextField1.getText()); //GENERANDO LOS VALORES ALEATORIOS DE LA MATRIZ m[i][j] Double m[][]= new Double [n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ m[i][j] = numerosAleatorios.nextDouble()*Double.parseDouble(jTextField2.getText()); valores=String.valueOf( m[i][j]); modelo2.addElement("["+(i+1)+"]"+"["+(j+1)+"]"+"-->"+valores); } }//CALCULANDO LA SUMA DE COLUMNAS if(jCheckBox2.isSelected()) { for(int k=0;k<n;k++){ for(int l=0;l<n;l++){ c=m[l][k]; } modelo1.addElement("la suma total de columnas "+(k+1)+" es: "+c); } }// CALCULANDO LA SUMA DE FILAS if(jCheckBox1.isSelected()) { for(int r=0;r<n;r++){ for(int s=0;s<n;s++){ c=m[r][s]; } modelo1.addElement("la suma total de fila "+(r+1)+" es: "+c); } } // CALCULANDO LA SUMA DE FILAS Y COLUMNAS if(jCheckBox3.isSelected()) { for(int t=0;t<n;t++){ for(int u=0;u<n;u++){ fc=m[t][u]; } modelo1.addElement("la suma total de fila "+(t+1)+" es: "+fc); }
MURGA RIVERA JEERY - 0201213054
} }
NUEVO – jButton5//LIMPIANDO LOS VALORES PARA INGRESAR LOS NUEVOS DATOSprivate void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { jTextField1.setText("");jTextField2.setText("");modelo1.clear();modelo2.clear();jCheckBox1.setSelected(false);jCheckBox2.setSelected(false);jCheckBox3.setSelected(false);jTextField1.requestFocus(); }
CERRAR – jButton4//CERRANDO EL PROGRAMAprivate void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { dispose (); }