Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FacturaEmitida extends Factura {
- private String emisor;
- private String cliente;
- FacturaEmitida(String cif, int numFactura, double total, String emisor, String cliente){
- super(cif,numFactura,total);
- this.emisor = emisor;
- this.cliente = cliente;
- }
- public void imprimirFactura() {
- System.out.println("CIF: " + this.getCif() + "n" +
- "Número de factura: " + this.getNumFactura() + "n" +
- "Emisor: " + this.getEmisor() + "n" +
- "Cliente: " + this.getCliente() + "n" +
- "Total: " + this.getTotal() + "n");
- }
- public class ValorNoValido extends Exception{
- public ValorNoValido(){ }
- public ValorNoValido(String cadena){
- super(cadena); //Llama al constructor de Exception y le pasa el contenido de cadena
- }
- }
- public void comprobarImporte() throws ValorNoValido {
- if(this.getTotal() < 0){
- throw new ValorNoValido("El importe total no puede ser negativo.");
- }
- }
- public String comprobarEmisor(String emisor){
- //name.trim().length() == 0
- if (this.getEmisor() == "" || this.getEmisor() == null) {
- this.emisor = "";
- throw new RuntimeException("El campo de Emisor no puede quedar vacío.");
- }
- return emisor;
- }
- /**
- * @return the emisor
- */
- public String getEmisor() {
- return emisor;
- }
- /**
- * @param emisor the emisor to set
- */
- public void setEmisor(String emisor) {
- this.emisor = emisor;
- }
- /**
- * @return the cliente
- */
- public String getCliente() {
- return cliente;
- }
- /**
- * @param cliente the cliente to set
- */
- public void setCliente(String cliente) {
- this.cliente = cliente;
- }
- }
- public class Factura {
- private String cif;
- private int numFactura;
- private double total;
- Factura(String cif, int numFactura, double total){
- this.cif = cif;
- this.numFactura = numFactura;
- this.total = total;
- }
- /**
- * @return the cif
- */
- public String getCif() {
- return cif;
- }
- /**
- * @param cif the cif to set
- */
- public void setCif(String cif) {
- this.cif = cif;
- }
- /**
- * @return the numFactura
- */
- public int getNumFactura() {
- return numFactura;
- }
- /**
- * @param numFactura the numFactura to set
- */
- public void setNumFactura(int numFactura) {
- this.numFactura = numFactura;
- }
- /**
- * @return the total
- */
- public double getTotal() {
- return total;
- }
- /**
- * @param total the total to set
- */
- public void setTotal(double total) {
- this.total = total;
- }
- }
- public class Main {
- public static void main(String[] args) {
- FacturaEmitida fact = new FacturaEmitida("844571X", 222, 1500, "", "Weist Cheing");
- try {
- fact.comprobarImporte();
- fact.comprobarEmisor(fact.getEmisor());
- fact.imprimirFactura();
- }catch (FacturaEmitida.ValorNoValido e) {
- System.out.println(e.getMessage());
- }catch(RuntimeException ex){
- System.out.println(ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement