..............................clase main................................
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package poo_mj_interfas;
/**
*
* @author SEDUCA
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Producto mouse=new Producto("Mouse",100);
System.out.println(mouse.calcularPrecioFinal());
System.out.println("El Iva es:" + mouse.calcularIva());
}
}
................................class Producto.........................................
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package poo_mj_interfas;
/**
*
* @author SEDUCA
*/
public class Producto implements Contable {
private String producto;
private double costo;
public Producto(String producto,double costo){
this.producto=producto;
this.costo=costo;
}
//implementacion de los metodos adstractos:
@Override
public double calcularIva(){
return calcularPrecioFinal()*IVA;
}
@Override
public double calcularPrecioFinal(){
return calcularPrecio()+calcularPrecio()*IVA;
}
//Metodo privados:
private double calcularPrecio(){
return (double)(this.costo+this.costo*GANANCIA);
}
}
............................interfas contable..................................
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package poo_mj_interfas;
/**
*
* @author SEDUCA
*/
public interface Contable {
//CONSTANTES:
public final double IVA=0.21;
public final double GANANCIA=0.5;
//METODOS ABSTRACTOS:
public double calcularPrecioFinal();
public double calcularIva();
}
No hay comentarios:
Publicar un comentario