Skip to content

Commit

Permalink
primeira solucao LAB4 -- arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
vinicius committed Jan 13, 2021
1 parent 636ed21 commit 85b451a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
72 changes: 53 additions & 19 deletions Album/src/Album.java
@@ -1,59 +1,93 @@
import java.util.ArrayList;

public class Album {

public static final int PERCENTUAL_MINIMO_PARA_AUTO_COMPLETAR = 90; // 90%

private Figurinha[] figurinhasColadas;

private int contRepetidas[];

private int totalFigurinhasColadas;

private int totalFigurinhasRepetidas;

private int quantFigurinhasPorPacotinho;

private int tamanhoDoAlbum;

public Album(int tamanhoDoAlbum, int quantFigurinhasPorPacotinho) {
// ToDo IMPLEMENT ME!!!!
figurinhasColadas = new Figurinha[tamanhoDoAlbum + 1];
contRepetidas = new int[tamanhoDoAlbum + 1];
this.quantFigurinhasPorPacotinho = quantFigurinhasPorPacotinho;
this.tamanhoDoAlbum = tamanhoDoAlbum;
}

public void receberNovoPacotinho(Pacotinho pacotinho) {
for (Figurinha fig : pacotinho) {


// ToDo IMPLEMENT ME!!
int posicao = fig.getPosicao();
if (figurinhasColadas[posicao] == null) {
// figurinha inédita!
colarFigurinhaInedita(fig);
} else {
// figurinha repetida!
contRepetidas[posicao]++;
totalFigurinhasRepetidas++;
}
}
}

private void colarFigurinhaInedita(Figurinha fig) {
figurinhasColadas[fig.getPosicao()] = fig;
totalFigurinhasColadas++;
}


public void autoCompletar() {
// verifica se o álbum já está suficientemente cheio
if (this.totalFigurinhasColadas >=
this.tamanhoDoAlbum * PERCENTUAL_MINIMO_PARA_AUTO_COMPLETAR / 100f) {
for (int i = 1; i <= this.tamanhoDoAlbum; i++) {
if (this.figurinhasColadas[i] == null) {
Figurinha fig = new Figurinha(i);
colarFigurinhaInedita(fig);
}
}
}

// ToDo IMPLEMENT ME!!
}

public int getTamanho() {
// ToDo IMPLEMENT ME!!!
return 0;
return this.tamanhoDoAlbum;
}

public int getQuantFigurinhasPorPacotinho() {
// ToDo IMPLEMENT ME!!!
return 0;
return this.quantFigurinhasPorPacotinho;
}

public int getQuantFigurinhasColadas() {
// ToDo IMPLEMENT ME!!!
return 0;
return this.totalFigurinhasColadas;
}

public int getQuantFigurinhasRepetidas() {
// ToDo IMPLEMENT ME!!!
return 0;
return this.totalFigurinhasRepetidas;
}

public boolean possuiFigurinhaColada(int posicao) {
// ToDo IMPLEMENT ME!!!
return false;
if (posicao < 1 || posicao > this.tamanhoDoAlbum) {
return false;
}
return this.figurinhasColadas[posicao] != null;
}

public boolean possuiFigurinhaRepetida(int posicao) {
// ToDo IMPLEMENT ME!!!
return false;
if (posicao < 1 || posicao > this.tamanhoDoAlbum) {
return false;
}
return this.contRepetidas[posicao] > 0;
}

public int getQuantFigurinhasFaltantes() {
// ToDo IMPLEMENT ME!!!
return 0;
return this.tamanhoDoAlbum - this.totalFigurinhasColadas;
}
}
6 changes: 4 additions & 2 deletions Album/src/Figurinha.java
@@ -1,13 +1,15 @@
public class Figurinha {

public Figurinha(int posicao) {
private int posicao;

public Figurinha(int posicao) {
this.posicao = posicao;
}

/**
* @return A posição que esta figurinha deve ocupar no álbum
*/
public int getPosicao() {
return 0; // ToDo IMPLEMENT ME!!!!
return this.posicao;
}
}
16 changes: 12 additions & 4 deletions Album/src/Pacotinho.java
@@ -1,9 +1,12 @@
import java.util.ArrayList;
import java.util.Random;

public class Pacotinho extends ArrayList<Figurinha> {

private Album album;

private static Random random = new Random();

// ToDo atributo que seja uma estrutura para guardar as figurinhas deste pacotinho

public Pacotinho(Album album) {
Expand All @@ -17,8 +20,14 @@ public Pacotinho(Album album, int[] posicoes) {
this.album = album;

// verificar se o tamanho do array está correto;
// caso não esteja, throw new RuntimeException("Pacotinho no tamanho errado!");
if (posicoes.length != album.getQuantFigurinhasPorPacotinho()) {
throw new RuntimeException("Pacotinho no tamanho errado!");
}

for (int posicao : posicoes) {
Figurinha fig = new Figurinha(posicao);
add(fig);
}
}

private void adicionarFigurinhasAleatorias() {
Expand All @@ -27,14 +36,13 @@ private void adicionarFigurinhasAleatorias() {

for (int i = 1; i <= quantFigurinhasPorPacotinho; i++) {
// ToDo sorteia uma posição entre 1 e o tamanho do álbum
int posicao = 0;
int posicao = 1 + random.nextInt(maxPosicao);


// ToDo cria um novo objeto Figurinha informando a posição sorteada
Figurinha figurinha = new Figurinha(posicao);

// ToDo adiciona ao pacotinho

Figurinha figurinha = new Figurinha(posicao);
add(figurinha);
}
}
Expand Down

0 comments on commit 85b451a

Please sign in to comment.