Doubt in exercise in java

0

I'm with the following exercise, and I'll put you where I got stuck, if you can give me a cable.

Exercise 2

Create a project Appliances, in it a package with the same name and an Appliances class (in singular) that includes

public class Electrodomestico {

    String numSerie;   

   String marca;

    double precio;

  //método (tipo get) que, aplicado sobre un objeto, accede al atributo numSerie del objeto y devuelve dicho atributo, es decir el número de serie

 String getNumSerie(){

return numSerie;

 }

//método (tipo set) que, aplicado sobre un objeto,  accede al atributo numSerie del objeto y lo modifica, cambiándolo por el que se ofrece como argumento (num)

 void setNumSerie(String num){

numSerie=num;

}  

/* el método anterior también se puede escribir     utilizando el operador this:

      void setNumSerie(String numSerie){

      this.numSerie=numSerie;

      }   */
  • Add the missing methods to the Appliances class to be able to consult and modify the value of all the attributes.

  • Create a default Constructor method that initializes the attributes to

    numSerie =”pendiente de asignar”
    
    marca="Balay"
    
    precio=120.99
    
  • Make a constructor method with arguments that correspond to the attributes of the class.

  • Create the following methods:

  • A method called apply_Iva that increases the price by 21%.
    Another method called discount_price that decreases the price in the percentage that we pass as an argument, controlling in the own method that the price does not get to be less than 10 euros, in that case we assign it of price 10.

    I have stuck at the point of creating method to lower_price. This is my code:

    public class Electrodomestico {
    
        String numSerie;   
    
        String marca;
    
        double precio;
    
      //método (tipo get) que, aplicado sobre un objeto, accede al atributo numSerie del objeto y devuelve dicho atributo, es decir el número de serie
    
        String getNumSerie(){
    
        return numSerie;
    
        }
        /* el método anterior también se puede escribir     utilizando el operador this:
    
          void setNumSerie(String numSerie){
    
          this.numSerie=numSerie;
    
          }   */
    
        void setNumSerie(String numSerie){
    
        this.numSerie=numSerie;
    
    }  
    
        String getMarca(){
    
        return marca;
    
        }
    
        void setMarca(String marca){
    
        this.marca=marca;
    
    
    }
    
        double getPrecio(){
    
        return precio;
    
        }
    
        void setPrecio(double precio){
    
        this.precio=precio;
    
    
    }
    
    Electrodomestico(){
    
        numSerie="Pendiente de asignar";
        marca="Balay";
        precio=120.99;
    }
    
    Electrodomestico(String numSerie,String marca, double precio){
    
        this.numSerie=numSerie;
        this.marca=marca;
        this.precio=precio;
    
    }
    
    public void aplicar_iva(){
    this.precio= (21*precio/100);
    
    }
    
    public void rebajar_precio(double precio){
    
    }
    
    }
    
        
    asked by 20.11.2018 в 20:22
    source

    1 answer

    1

    I share a pseudocode that could help you:

    RebajarPrecio (duoble porcentajeDescuento)
    {
       precio = precio - (precio * porcentajeDescuento)
       Si (precio < 10){//Validas que el nuevo precio no sea menor a 10 euros
        precio=10
      }
    }
    
        
    answered by 20.11.2018 / 20:45
    source