Java - Consulta con programa

 
Vista:
sin imagen de perfil

Consulta con programa

Publicado por Alejandro (14 intervenciones) el 29/09/2016 16:41:27
Buenos días llevo varios dias intentando crear un programa de correspondencias y aplicaciones (inyectiva, suprayectiva, biyectiva, unívoca, multívoca, aplicación inyectiva y aplicación suprayectiva.
Anexo el códgio que llevo hasta el momento:
package relacionesbinarias;

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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
 
/**
 *
 * @author Jonathan Alejandro Gutiérrez Hernández
 */
public class relacionesBinarias extends javax.swing.JFrame implements ActionListener{
 
    /**
     * Creates new form relacionesBinarias
     */
    public relacionesBinarias() {
        initComponents();
        JBEvaluar.addActionListener(this);
    }
    private void Evaluar(){
 
        a = JTFA.getText();
        b = JTFB.getText();
        f = JTFF.getText();
 
        StringTokenizer a1=new StringTokenizer(a, ",");
        StringTokenizer b1=new StringTokenizer(b, ",");
        StringTokenizer f1=new StringTokenizer(f, ",");
 
        int nDatos =a1.countTokens();
 
        while(f1.hasMoreElements()){
            tok1=f1.nextToken();
        }
            while(a1.hasMoreElements()){
                tok=a1.nextToken();
                while(b1.hasMoreElements()){
                    sumaDeCadenas =" "+ tok+b1.nextToken();
                    System.out.println(sumaDeCadenas);
 
                }
            }
            if(tok1.contains(sumaDeCadenas)){
                System.out.println(tok1);
            }
    }
 
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        JBEvaluar = new javax.swing.JButton();
        JTFA = new javax.swing.JTextField();
        JTFB = new javax.swing.JTextField();
        JTFF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Tipos de Correspondencias");
 
        JBEvaluar.setText("Evaluar");
        JBEvaluar.setToolTipText("");
 
        JTFB.setHorizontalAlignment(javax.swing.JTextField.LEFT);
 
        jLabel1.setText("A");
 
        jLabel2.setText("B");
 
        jLabel3.setText("f");
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(155, 155, 155)
                        .addComponent(JBEvaluar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(2, 2, 2))
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(JTFA, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
                            .addComponent(JTFB)
                            .addComponent(JTFF))))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JTFA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JTFB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JTFF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(31, 31, 31)
                .addComponent(JBEvaluar)
                .addGap(29, 29, 29))
        );
 
        pack();
    }// </editor-fold>                        
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(relacionesBinarias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(relacionesBinarias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(relacionesBinarias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(relacionesBinarias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new relacionesBinarias().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton JBEvaluar;
    private javax.swing.JTextField JTFA;
    private javax.swing.JTextField JTFB;
    private javax.swing.JTextField JTFF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration                   
    private String a;
    private String b;
    private String f;
    private String sumaDeCadenas;
    private String tok;
    private String tok1;
    private String tok2;
 
    @Override
    public void actionPerformed(ActionEvent e) {
        Object fuente= e.getSource();
        if(fuente==JBEvaluar){
            Evaluar();
        }else{
            JOptionPane.showConfirmDialog(relacionesBinarias.this, "No es una correspondencia");
        }
    }
}

Agradecería su ayuda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Consulta con programa

Publicado por YYanes (144 intervenciones) el 29/09/2016 17:08:57
Amigo, pues diga cuál es su duda en concreto, no esperará que alguien tome tooooodo ese código y lo compile para ver qué le falta y luego se lo termine, ¿o sí?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Consulta con programa

Publicado por Alejandro (14 intervenciones) el 29/09/2016 19:15:43
la duda seria que podria implementar para compararlos y así decidir si es correspondencia o aplicación ¿podría ser arraylist o un mapa?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar