Está en la página 1de 1

public class Coche {

//----Definición de atributos----
private String colorCoche;
private String tipoCoche;
private int velocidadCoche;
private String marcaCoche;
//------------------------------------
public Coche(String color, String tipo, int velocidad, String marca){
this.colorCoche = color;
this.tipoCoche = tipo;
this.velocidadCoche = velocidad;
this.marcaCoche = marca;
}
//-------------------------------------
//----Definición de métodos----
public void arrancar(){
this.velocidadCoche=10;
}

public void frenar(){


this.velocidadCoche=0;
}

public void acelerar(int velocidadAcelerada){


this.velocidadCoche+=velocidadAcelerada;
}

public void estadoCoche(){


if(this.velocidadCoche>0){
System.out.println("El coche está en movimiento, velocidad
=:"+this.velocidadCoche);
}else{
System.out.println("El coche esta detenido");
}
}
//------------------------------------------------------
//----Método principal que permite ejecutar la clase----
public static void main(String[] args){
Coche miCoche = new Coche("Rojo", "deportivo",120,"Mazda");
Coche suCoche = new Coche("Amarillo","taxi",110,"Reanult");
Coche tuCoche = new Coche ("Azul","Deportivo",200,"Mercedes");

miCoche.arrancar();
miCoche.acelerar(90);
miCoche.estadoCoche();

suCoche.arrancar();
suCoche.acelerar(80);
suCoche.frenar();
suCoche.estadoCoche();

tuCoche.arrancar();
tuCoche.acelerar(100);
tuCoche.estadoCoche();
}
//------------------------------------------------------
}

También podría gustarte