GUI:
PROCESO:
protected void actionPerformedBtnProcesar(ActionEvent arg0) {
//CÓDIGO DE MI BOTÓN PROCESAR
//DECLARO VARIABLES LOCALES:
int tipo,cant;
double icom,idesc,ipag;
//LLAMO MIS MÉTODOS
tipo=getTipo();
cant=getCantidad();
icom=calcularImporteComprar(tipo,cant);
idesc=calcularImporteDescuento(cant,icom);
ipag=calcularImportePagar(icom,idesc);
mostrarResultados(icom,idesc,ipag);
}
//DEFINO LAS FUNCIONES DE MIS MÉTODOS
//METODO 1
int getTipo(){
return cboTipo.getSelectedIndex();
}
//METODO 2
int getCantidad(){
return Integer.parseInt(txtCantidad.getText());
}
//METODO 3
double calcularImporteComprar(int ti, int ca){
switch(ti){
case 0: return 2000.00*ca;
case 1: return 2456.78*ca;
case 2: return 1756.90*ca;
default: return 1987.20*ca;
}
}
//METODO 4
double calcularImporteDescuento(int ca, double ic){
if(ca<=2)
return 0*ic;
else
if(ca<=4)
return 0.064*ic;
else
if(ca<=6)
return 0.09*ic;
else
return 0.0114*ic;
}
//METODO 5
double calcularImportePagar(double ic, double id){
return ic-id;
}
//MOSTRAR RESULTADOS
void mostrarResultados(double ic, double id, double ip){
txtS.setText(«Estos son los resultados:»+»\n\n»);
txtS.append(«El importe de compra es: «+ic+»\n»);
txtS.append(«El descuento es de :» +id+»\n»);
txtS.append(«El importe a pagar es: «+ip+»\n»);
}
protected void actionPerformedBtnBorrar(ActionEvent arg0) {
//CÓDIGO DE MI BOTÓN BORRAR
//LLAMO AL MÉTODO
BorrarTodo();
}
//DEFINO EL MÉTODO
void BorrarTodo(){
txtS.setText(«»);
txtCantidad.setText(«»);
txtCantidad.requestFocus();
cboTipo.setSelectedIndex(0);
}
}
