SEGUNDA PRACTICA PROGRAMANDO EN JAVA

PRACTICANDO EN JAVA

SEGUNDA PRACTICA: Desarrollar un formulario que calcule el total a pagar por un cliente. Primero se seleccionará con las casillas de verificación los productos deseados (puede marcar uno o varios). Adicional mente se podrá seleccionar el tipo de descuento.

PRIMERO TRABAJAREMOS EN LA INTERFAZ.


le asignaremos los siguientes nombres para cada herramienta

Para los RadioButtons

rb1. rb2. rb3  (nombres respectivamente)

PARA LOS CHECKBOX

chk1, chk2, chk3 (nombres respectivamente)

PARA  LOS TEXTBOX

txtcta, txttotal, txtdto, txtneto  (nombres respectivamente)


PARA EL BOTON 

btncalcular  (nombre respectivamente)


iniciamos programando en el botón calcular hacemos clic  en dicho botón

CÓDIGO EN EL BUTTON 




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

        // toda la programacion en este button
        
        // PRIMERO DECLARAMOS VARIABLES
        
        double cuenta =0;
        double total=0;
        double descuento =0;
        
        // CALCULAMOS LOS COSTOS
        
        if(chk1.isSelected()){   // si esta seleccionado
        
        cuenta++; // (aumenta el contador)
        
        total +=45;
       
        
        }
        
        if(chk2.isSelected()){
        
        cuenta++;
        
        total +=20;
        }
        
        if (chk3.isSelected()){
        
        cuenta++;
        total +=35;
        
        }
        
        //CALCULAMOS LOS DESCUENTOS
        
       if(rb3.isSelected()){
       descuento = 0.10 * total;
       
       }
       
       else if (rb2.isSelected()){
       
           descuento=0.05+total;
           
       }
       else
       {
       descuento=0;
       
       }
       
       // VISUALIZAREMOS LOS RESULTADOS
       
       txtcta.setText(String.valueOf(cuenta));
       txttotal.setText(String.valueOf(total));
       txtdto.setText(String.valueOf(descuento));
       txtneto.setText(String.valueOf(total-descuento));
       
        
    }                                           












Share:

Anuncio de Enlaces

Buscar este blog

  • ()
  • ()
Mostrar más
Todos los derechos reservados por AITRAQUER. Con la tecnología de Blogger.

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Pages

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.