Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Producto
CASE
Microprocesador
Memoria
Mainboard
Disco Duro
Monitor
Teclado
Mouse
Costo (US $)
32.00
75
48
70
120
130
5
5
Lector de CD ROM
12
Adicionalmente que tipo de descuento se har efectivo, existen las
siguientes posibilidades: 0%, 5%, 8% (Deben representarse con
radiobuttons)
Calcular el costo total de los productos y el descuento pertinente.
Crear el diseo de formulario de acuerdo a su criterio, utilice controles
checkbox (casillas de verificacin) y radiobuttons (botones de
opcin de grupo).
Codificacin java
public class factura
extends javax.swing.JFrame
{
public factura()
{
initComponents();
}
SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CL
OSE);
jLabel1.setText("$.32");
jLabel2.setText("$.75");
jLabel3.setText("$.48");
jLabel4.setText("$.70");
jLabel5.setText("$.120");
jLabel6.setText("$.130");
jLabel7.setText("$.5");
jLabel8.setText("$.5");
jLabel9.setText("$.12");
jLabel10.setText("Seleccione Producto");
jLabel11.setText("Descuento");
check1.setText("CASE");
check2.setText("Microprocesador");
check3.setText("Memoria");
check4.setText("Mainboard");
check5.setText("Disco Duro");
check6.setText("Monitor");
check6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
check6ActionPerformed(evt);
}
});
check7.setText("Teclado");
check8.setText("Mouse");
check9.setText("Lector de CD ROM");
rb0.setText("0%");
rb5.setText("5%");
rb8.setText("8%");
jLabel12.setText("Elementos Selecionados");
jLabel13.setText("Total a Pagar:");
jLabel14.setText("Total de Descuento:");
jLabel15.setText("Neto a Pagar");
txttotalapagar.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txttotalapagarActionPerformed(evt);
}
});
calcular.setText("Calcular");
calcular.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calcularActionPerformed(evt);
}
});
jButton1.setText("Limpiar");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
.addComponent(check7)
.addComponent(check8))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9)))
.addGroup(layout.createSequentialGroup()
.addComponent(check1)
.addGap(79, 79, 79)
.addComponent(jLabel1)))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(83, 83, 83)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(rb0)
.addComponent(jLabel11)
.addComponent(rb5)
.addComponent(rb8)))
.addGroup(layout.createSequentialGroup()
.addGap(109, 109, 109)
.addComponent(jLabel12))
.addGroup(layout.createSequentialGroup()
.addGap(124, 124, 124)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addComponent(calcular)
.addComponent(txtelementosseleccionados,
javax.swing.GroupLayout.PREFERRED_SIZE, 59,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel14)
.addComponent(jLabel13)
.addComponent(jLabel15))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNR
ELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING, false)
.addComponent(txttotalapagar,
javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
.addComponent(txttotaldedescuento)
.addComponent(txtnetoapagar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 88,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(157, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(layout.createSequentialGroup()
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel1)
.addComponent(check1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel2)
.addComponent(check2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel3)
.addComponent(check3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel4)
.addComponent(check4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel5)
.addComponent(check5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel6)
.addComponent(check6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel7)
.addComponent(check7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel8)
.addComponent(check8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel9)
.addComponent(check9)))
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(rb0)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(rb5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(rb8)
.addGap(18, 18, 18)
.addComponent(jLabel12)
.addGap(18, 18, 18)
.addComponent(txtelementosseleccionados,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(calcular)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(jLabel13)
.addComponent(txttotalapagar,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel14)
.addComponent(txttotaldedescuento,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addComponent(jLabel15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(txtnetoapagar,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 47,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(58, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void
txttotalapagarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
txttotalapagar.setText("");
txttotaldedescuento.setText("");
txtnetoapagar.setText("");
here:
double total=0;
double descuento=0;
if (check1.isSelected())
cuenta++;
total+=32;
if (check2.isSelected())
cuenta++;
total+=75;
if (check3.isSelected())
cuenta++;
total+=48;
if (check4.isSelected())
cuenta++;
total+=70;
if (check5.isSelected())
cuenta++;
total+=120;
if (check6.isSelected())
cuenta++;
total+=130;
if (check7.isSelected())
cuenta++;
total+=5;
if (check8.isSelected())
cuenta++;
total+=5;
if (check9.isSelected())
{
cuenta++;
total+=12;
if (rb8.isSelected())
{
descuento=0.8*total;
}
if(rb5.isSelected())
descuento=0.05*total;
}
else if (rb0.isSelected())
descuento=0;
txtelementosseleccionados.setText(String.valueOf(cuenta));
txttotalapagar.setText(String.valueOf(total));
txttotaldedescuento.setText(String.valueOf(descuento));
txtnetoapagar.setText(String.valueOf(total-descuento));
TODO add your handling code here:
}
//
/**
* @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.ht
ml
*/
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(factura.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(factura.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(factura.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
Imgenes
CASO PROPUESTO 2
Crear una aplicacin Java que resuelva el siguiente caso prctico:
Se necesita una aplicacin informtica que ayude a calcular los
haberes mensuales de los trabajadores de una empresa, para lo cual
se le pide a Ud. que desarrolle el siguiente programa:
Luego de ingresar el monto de sueldo bsico mensual, se debe
seleccionar con casillas de verificacin, las bonificaciones a las cuales
el trabajador est afecto (pueden ser una, varias o ninguna).
Tipo de Bonificacin
Porcentaje de
Bonificacin con
relacin al sueldo
bsico
8%
10%
S/. 150.00
Familiar
Productividad
Escolaridad
Porcentaje de
Tipo de Sistema de
Descuento con
Administracin de
relacin al sueldo
Pensiones
bsico
11%
de
13%
Fondo de Pensiones)
Luego
de
seleccionar
las
bonificaciones
el
tipo
de
sistema
de
sueldo2=((n1*10)/100)+n1;
if (check1.isSelected());
{
cuenta++;
total+=((n1*8)/100));
}
if (check2.isSelected());
{
Cuenta++;
}
total+=((n1*10)/100);
}
if (check3.isSelected());
{
Cuenta++;
}
total+=150;
{
if (radio1.isSelected());
}
descuento=0.11*(total+n1);
{
if (radio2.isSelected());
}
descuento=0.13*(total+n1);
{
txtbonificacion.setText(String.valueOf(total+n1));
txtdescuento.setText(String.valueOf(descuento));
txtrecibir.setText(String.valueOf((total+n1)-descuento));
txt1.setText(String.valueOf(cuenta));
txtingresesueldo.setText();
txtbonificacion.setText();
txtdescuento.setText();
txtrecibir.setText( );
txt1.setText( );
txtingresesueldo.grabFocus();