Created
November 6, 2017 15:27
-
-
Save Bigomby/eafa07d5cd140f484e9954aa7c2a6ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
interface Servicio { | |
void asignarValor(int valor); | |
int getValor(); | |
} | |
class Servicio1 implements Servicio { | |
private int valor; | |
public void asignarValor(int valor) { | |
this.valor = valor; | |
} | |
public int getValor() { | |
return this.valor; | |
} | |
} | |
class Servicio2 implements Servicio { | |
private int valor; | |
public void asignarValor(int valor) { | |
this.valor = valor; | |
} | |
public int getValor() { | |
return this.valor; | |
} | |
} | |
class Servicio3 implements Servicio { | |
private int valor; | |
public void asignarValor(int valor) { | |
this.valor = valor; | |
} | |
public int getValor() { | |
return this.valor; | |
} | |
} | |
class Main { | |
public static void main(String[] args) { | |
int pasadas = 3; | |
ArrayList<Servicio> servicios = new ArrayList<Servicio>(); | |
Servicio servicio1 = new Servicio1(); | |
servicios.add(servicio1); | |
Servicio servicio2 = new Servicio2(); | |
servicios.add(servicio2); | |
Servicio servicio3 = new Servicio3(); | |
servicios.add(servicio3); | |
for (int i = 0; i < pasadas; i++) { | |
Servicio servicio = servicios.get(i); | |
servicio.asignarValor(i); | |
System.out.println(servicio.getValor()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment