You are on page 1of 6

1.

- Desarrollar una aplicación que permita ingresar un número que lo permita convertir en
letras
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package conversion;

/**
*
* @author IESTP-JDCH
*/
public class numero extends javax.swing.JApplet {

/**
* Initializes the applet numero
*/
@Override
public void init() {
/*
* 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(numero.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(numero.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(numero.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(numero.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/*
* Create and display the applet
*/
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {

public void run() {


initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

/**
* This method is called from within the init() method 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() {

jLabel1 = new javax.swing.JLabel();


jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();

jLabel1.setText("Ingrese un numero");

jButton1.setText("Convertir");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel2.setText("El numero en letras es");

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(46, 46, 46)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(jLabel2)))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(jTextField1)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 163,
Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(54, 54, 54))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(160, Short.MAX_VALUE))
);
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
int numero;
int numeva;
int numdig;
int candig;
int N[]= new int[100];
int i=1;
String tipo,rpta,temp;
rpta="";
tipo="";
temp="";
numero=Integer.parseInt(jTextField1.getText());
numeva=numero;
candig=0;
i=1;
while (numeva>0)
{
numdig=numeva%10;
N[i]=numdig;
numeva=numeva/10;
candig=candig+1;
i++;
}

for(i=1;i<=candig;i++)
{
System.out.println(N[i]);
}

switch(candig)
{
case 1:
tipo="Unidades";
N[1]=N[1]*1;
break;
case 2:
tipo="Decenas";
N[2]=N[2]*10;
break;
case 3:
tipo="Centenas";
N[2]=N[2]*10;
N[3]=N[3]*100;
break;
case 4:
tipo="Millares";
N[2]=N[2]*10;
N[3]=N[3]*100;
N[4]=N[4]*100;
break;
}

while(candig>0)
{
numero=N[candig];
switch(numero)
{

case 0:
rpta="Cero";
break;
case 1:
rpta="Uno";
break;
case 2:
rpta="Dos";
break;
case 3:
rpta="Tres";
break;
case 4:
rpta="Cuatro";
break;
case 5:
rpta="Cinco";
break;
case 6:
rpta="Seis";
break;
case 7:
rpta="Siete";
break;
case 8:
rpta="Ocho";
break;
case 9:
rpta="Nueve";
break;
case 10:
rpta="Diez";
break;
case 11:
rpta="Once";
break;
case 12:
rpta="Doce";
break;
case 13:
rpta="Trece";
break;
case 14:
rpta="Catorce";
break;
case 20:
rpta="Veinte";
break;
case 30:
rpta="Treinta";
break;
case 40:
rpta="Cuarenta";
break;
case 50:
rpta="Cincuenta";
break;
case 60:
rpta="Sesenta";
break;
case 70:
rpta="Setenta";
break;
case 80:
rpta="Ochenta";
break;
case 90:
rpta="Noventa";
break;
case 100:
rpta="Cien";
break;
case 200:
rpta="Doscientos";
break;
case 300:
rpta="Trescientos";
break;
case 400:
rpta="Cuatrocientos";
break;
case 500:
rpta="Quinientos";
break;
case 600:
rpta="Seiscientos";
break;
case 700:
rpta="Seiscientos";
break;
case 800:
rpta="Ochocientos";
break;
case 900:
rpta="Novecientos";
break;
case 1000:
rpta="Mil";
break;
}
temp=temp+rpta;
candig=candig-1;
jTextField2.setText(""+temp);
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}

You might also like