Skip to content

Instantly share code, notes, and snippets.

@prinick96
Created October 18, 2016 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prinick96/82085df17a85bf3a25d46f9403643dbb to your computer and use it in GitHub Desktop.
Save prinick96/82085df17a85bf3a25d46f9403643dbb to your computer and use it in GitHub Desktop.
class Electrodomesticos {
private double precio;
private String color;
private char consumo;
private double peso;
public double getPrecio() {
return this.precio;
}
public String getColor() {
return this.color;
}
public char getConsumo() {
return this.consumo;
}
public double getPeso() {
return this.peso;
}
private double calcularPrecio() {
double pesoPorPrecio = 0;
this.comprobarConsumoEnergetico(this.consumo);
if(this.peso >= 0 && this.peso <= 19) {
pesoPorPrecio = 19;
} else if(this.peso >= 20 && this.peso <= 49) {
pesoPorPrecio = 50;
} else if(this.peso >= 50 && this.peso <= 79) {
pesoPorPrecio = 80;
} else {
pesoPorPrecio = 100;
}
this.precio += pesoPorPrecio;
return this.precio;
}
Electrodomesticos() {
this.color = "Blanco";
this.consumo = 'F';
this.peso = 5;
this.precio = 100.00;
}
Electrodomesticos(double precio, double peso) {
this.color = "Blanco";
this.consumo = 'F';
this.peso = peso;
this.precio = precio;
}
Electrodomesticos(double precio, double peso, String color, char consumo) {
this.precio = precio;
this.peso = peso;
this.comprobarColor(this.color);
this.consumo = consumo;
}
public void comprobarConsumoEnergetico(char letra) {
boolean exist = false;
switch(letra) {
case 'A':
exist = true;
this.precio = 100.00;
break;
case 'B':
exist = true;
this.precio = 80.00;
break;
case 'C':
exist = true;
this.precio = 60.00;
break;
case 'D':
exist= true;
this.precio = 50.00;
break;
case 'E':
exist = true;
this.precio = 30.00;
break;
case 'F':
exist = true;
this.precio = 10.00;
break;
}
if(exist) {
this.consumo = letra;
}
}
public void comprobarColor(String color) {
if(color == "Negro" || color == "Azul"
|| color == "Gris" || color == "Rojo") {
this.color = color;
} else {
this.color = "Blanco";
}
}
public double precioFinal() {
return calcularPrecio();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment