Created
December 11, 2011 18:41
-
-
Save danielfariati/1462028 to your computer and use it in GitHub Desktop.
Desafio Concrete Solutions 2
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
package br.com.concretesolutions.desafio; | |
import java.util.ArrayList; | |
public class Pessoa { | |
public static final int MARGUERITA = 0; | |
public static final int QUATRO_QUEIJOS = 1; | |
public static final int ESCAROLA = 2; | |
public static final int PORTUGUESA = 3; | |
public static final int FRANGO_CATUPIRY = 4; | |
public static final int NAPOLITANA = 5; | |
private String nome; | |
private ArrayList<Integer> notas; | |
public Pessoa(String nome, int notaMarguerita, int notaQuatroQueijos, int notaEscarola, int notaPortuguesa, int notaFrangoCatupiry, int notaNapolitana) { | |
this.nome = nome; | |
notas = new ArrayList<Integer>(); | |
notas.add(MARGUERITA, notaMarguerita); | |
notas.add(QUATRO_QUEIJOS, notaQuatroQueijos); | |
notas.add(ESCAROLA, notaEscarola); | |
notas.add(PORTUGUESA, notaPortuguesa); | |
notas.add(FRANGO_CATUPIRY, notaFrangoCatupiry); | |
notas.add(NAPOLITANA, notaNapolitana); | |
} | |
public static void main(String[] args) { | |
Pessoa anfitriao = new Pessoa("Luca", 5, 4, 3, 4, 3, 2); | |
ArrayList<Pessoa> listaPossiveisConvidados = new ArrayList<Pessoa>(); | |
listaPossiveisConvidados.add(new Pessoa("Renato", 4, 5, 4, 5, 4, 3)); | |
listaPossiveisConvidados.add(new Pessoa("Marcelo", 2, 2, 1, 3, 5, 2)); | |
listaPossiveisConvidados.add(new Pessoa("Lenon", 4, 5, 2, 1, 1, 3)); | |
listaPossiveisConvidados.add(new Pessoa("Renata", 4, 5, 1, 1, 3, 4)); | |
listaPossiveisConvidados.add(new Pessoa("Washington", 1, 1, 2, 3, 4, 3)); | |
listaPossiveisConvidados.add(new Pessoa("Tino", 1, 5, 1, 4, 3, 2)); | |
Pessoa convidado = Pessoa.determinarConvidado(anfitriao, listaPossiveisConvidados); | |
System.out.println("Você deve convidar a pessoa: " + convidado.nome); | |
} | |
public static Pessoa determinarConvidado(Pessoa anfitriao, ArrayList<Pessoa> listaPossiveisConvidados) { | |
Pessoa convidado = null; | |
int menorDiff = Integer.MAX_VALUE; | |
for (Pessoa candidato : listaPossiveisConvidados) { | |
int diff = 0; | |
for (int i = 0; i < candidato.notas.size(); i++) { | |
diff += compararNotas(candidato.notas.get(i), anfitriao.notas.get(i)); | |
} | |
System.out.println("A diferença entre " + anfitriao.nome + " e " + candidato.nome + " é de " + diff + " pontos."); | |
if (diff < menorDiff) { | |
convidado = candidato; | |
menorDiff = diff; | |
} | |
} | |
return convidado; | |
} | |
public static int compararNotas(Integer nota1, Integer nota2) { | |
return (nota1 > nota2) ? nota1 - nota2 : nota2 - nota1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment