Skip to content

Instantly share code, notes, and snippets.

@anabastos
Last active June 20, 2017 19:27
Show Gist options
  • Save anabastos/b86dad9a3c48da999859ef24784095dc to your computer and use it in GitHub Desktop.
Save anabastos/b86dad9a3c48da999859ef24784095dc to your computer and use it in GitHub Desktop.
class Tabuada {
private int row;
public Tabuada(int numero) {
this.numero = numero;
System.out.println("Tabuada do : " + this.numero);
}
void report(int multiplicador) {
public static int multiplicacao = numero * multiplicador
System.out.print(" " + multiplicacao);
}
}
class Factory {
private Tabuada[] pool;
public Factory(int maxRows) {
tabela = new Tabuada[maxRows];
}
public Tabuada getFlyweight(int numero) {
if (tabela[numero] == null) {
tabela[numero] = new Tabuada(numero);
}
return tabela[numero];
}
}
public class FlyweightTabuada {
public static final int tamanho = 11;
//TAREFA: Faça a tabuada do 10
public static void main(String[] args) {
for (int i=0; i < tamanho; i++) {
for (int j=0; j < 10; j++)
}
}
}
//RESPOSTA:
public class FlyweightTabuada {
public static final int tamanho = 11;
//TAREFA: Faça a tabuada até o 10
public static void main(String[] args) {
Factory tabuadaDo10 = new Factory(tamanho);
for (int i=0; i < tamanho; i++) {
for (int j=0; j < 10; j++)
tabuadaDo10.getFlyweight(i).report(j);
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment