Sunteți pe pagina 1din 12

UNIVERSIDAD PRIVADA TELESUP

INSTRUCCIONES

CASO PROPUESTO 1
Se necesita una aplicacin informtica que calcule el total a facturar por la
compra de los siguientes productos (debe representarse con casillas de
verificacin):

Producto

Costo (US $)

CASE
Microprocesador
Memoria
Mainboard
Disco Duro
Monitor
Teclado
Mouse

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).

DESARROLLO:
Java:

public class factura extends javax.swing.JFrame {


public factura() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();

UNIVERSIDAD PRIVADA TELESUP


jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
check1 = new javax.swing.JCheckBox();
check2 = new javax.swing.JCheckBox();
check3 = new javax.swing.JCheckBox();
check4 = new javax.swing.JCheckBox();
check5 = new javax.swing.JCheckBox();
check6 = new javax.swing.JCheckBox();
check7 = new javax.swing.JCheckBox();
check8 = new javax.swing.JCheckBox();
check9 = new javax.swing.JCheckBox();
rb0 = new javax.swing.JRadioButton();
rb5 = new javax.swing.JRadioButton();
rb8 = new javax.swing.JRadioButton();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
txtelementosseleccionados = new javax.swing.JTextField();
txttotalapagar = new javax.swing.JTextField();
txttotaldedescuento = new javax.swing.JTextField();
txtnetoapagar = new javax.swing.JTextField();
calcular = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
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");

UNIVERSIDAD PRIVADA TELESUP


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);
}
});

UNIVERSIDAD PRIVADA TELESUP


jButton1.setText("Limpiar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
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.L
EADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jLabel10))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addComponent(check9)
.addComponent(check2)
.addComponent(check3)
.addComponent(check4)
.addComponent(check5)
.addComponent(check6)
.addComponent(check7)
.addComponent(check8))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9)))
.addGroup(layout.createSequentialGroup()

UNIVERSIDAD PRIVADA TELESUP


.addComponent(check1)
.addGap(79, 79, 79)
.addComponent(jLabel1)))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addGroup(layout.createSequentialGroup()
.addGap(83, 83, 83)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.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.Alignment.T
RAILING)
.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.Alignment.L
EADING)
.addComponent(jLabel14)
.addComponent(jLabel13)
.addComponent(jLabel15))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATE
D)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING, false)
.addComponent(txttotalapagar,
javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
.addComponent(txttotaldedescuento)
.addComponent(txtnetoapagar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
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(

UNIVERSIDAD PRIVADA TELESUP


layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel1)
.addComponent(check1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel2)
.addComponent(check2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel3)
.addComponent(check3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel4)
.addComponent(check4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel5)
.addComponent(check5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel6)

UNIVERSIDAD PRIVADA TELESUP


.addComponent(check6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel7)
.addComponent(check7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel8)
.addComponent(check8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.addComponent(jLabel9)
.addComponent(check9)))
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(rb0)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rb5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.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.Alignment.L
EADING)
.addComponent(jLabel13)
.addComponent(txttotalapagar,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)

UNIVERSIDAD PRIVADA TELESUP


.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.Alignment.T
RAILING)
.addComponent(jLabel15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.B
ASELINE)
.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 check6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txttotalapagarActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
txtelementosseleccionados.setText("");
txttotalapagar.setText("");
txttotaldedescuento.setText("");
txtnetoapagar.setText("");

// TODO add your handling code here:

}
private void calcularActionPerformed(java.awt.event.ActionEvent evt) {
double cuenta=0;
double total=0;
double descuento=0;
if (check1.isSelected())

UNIVERSIDAD PRIVADA TELESUP


{
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())
{

UNIVERSIDAD PRIVADA TELESUP


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;

UNIVERSIDAD PRIVADA TELESUP


}
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));
add your handling code here:
}

// TODO

/**
* @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(factura.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(factura.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(factura.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);

UNIVERSIDAD PRIVADA TELESUP


} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(factura.class.getName()).log(java.util.logg
ing.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new factura().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton calcular;
private javax.swing.JCheckBox check1;
private javax.swing.JCheckBox check2;
private javax.swing.JCheckBox check3;
private javax.swing.JCheckBox check4;
private javax.swing.JCheckBox check5;
private javax.swing.JCheckBox check6;
private javax.swing.JCheckBox check7;
private javax.swing.JCheckBox check8;
private javax.swing.JCheckBox check9;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JRadioButton rb0;
private javax.swing.JRadioButton rb5;
private javax.swing.JRadioButton rb8;
private javax.swing.JTextField txtelementosseleccionados;
private javax.swing.JTextField txtnetoapagar;
private javax.swing.JTextField txttotalapagar;
private javax.swing.JTextField txttotaldedescuento;
// End of variables declaration