Sei sulla pagina 1di 26

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

// <editor-fold defaultstate="collapsed" desc="Generated Code">


private void initComponents()
{

jLabel1 = new javax.swing.JLabel();


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

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jLabel10))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.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.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 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("");
here:

// TODO add your handling code

private void calcularActionPerformed(java.awt.event.ActionEvent


evt) {
double cuenta=0;

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

} catch (javax.swing.UnsupportedLookAndFeelException ex) {


java.util.logging.Logger.getLogger(factura.class.getName()).log(java.u
til.logging.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
}

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

Adicionalmente sealar el sistema de pensiones al cual est afiliado el


trabajador (slo se puede escoger una de cualquiera de las dos
opciones)

Porcentaje de

Tipo de Sistema de

Descuento con

Administracin de

relacin al sueldo

Pensiones

bsico
11%

SNP (Sistema Nacional de


Pensiones)
AFP (Administracin

de

13%

Fondo de Pensiones)
Luego

de

seleccionar

las

bonificaciones

el

tipo

de

sistema

de

administracin de pensiones hacer click en el botn calcular, para hallar: el


monto total de la bonificacin, el monto total de descuento y el neto a
percibir.
Crear el diseo de formulario de acuerdo a su criterio y lo enseado en la
ltima clase, utilice controles checkbox (casillas de verificacin) y
radiobuttons (botones de opciones de grupo)

Java Application / luego en Next


Project Name: nombre
New / JFrame Form
Class name, le ponen un nombre.
Variable Name/ *poner: txtingresesueldo */
Name/* poner: txtbonificacion */
Change Variable Name/* poner: txtdescuento* /
Change Variable Name/ *poner: txtresibir* /
Change Variable Name/* poner: txt1 */
/ Edit text/ poner: Ingrese Sueldo;
/ Edit text/ poner: Seleccione Bonificacin;

/ Edit text/ poner: Seleccione Bonificacin (descuento);


/ Edit text/ poner: 8 %;
/ Edit text/ poner: 10 %;
Edit text/ poner: s/.150.00;
/ Edit text/ poner: 11 %;
/ Edit text/ poner: 13%;
/ Edit text/ poner: Total con Bonificacin:
/ Edit text/ poner: Total de Descuento:
/ Edit text/ poner:Total Neto a Recibir:
/ Edit text/ poner: SNP (Sistema Nacional de Pensiones)
Change Variable Name/ poner: radio1/
/ Edit text/ poner: AFP (Administracin de Fondo de pensiones)
/ Change Variable Name/ poner: radio2 /
/ Edit text/ poner: Familiar:
/ Change Variable Name/ poner: check1 /
/ Edit text/ poner: Productividad:
/ Change Variable Name/ poner: check2 /
/ Edit text/ poner: Escolaridad:
/ Change Variable Name/ poner: check3
/ Edit text/ poner: Calcular
/ Change Variable Name/ poner: botoncalcular /
double sueldo1=0;
double sueldo2=0;
int cuenta=0;
double n1=0;
double total=0;
double descuento=0;
n1=Double.parseDouble(txtingresesueldo.getText());
sueldo1=((n1*8)/100)+n1;

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

Potrebbero piacerti anche