diff --git a/labs/lab03/Enunciado.pdf b/labs/lab03/Enunciado.pdf new file mode 100644 index 0000000..d4efb3b Binary files /dev/null and b/labs/lab03/Enunciado.pdf differ diff --git a/labs/lab03/Sobrenome não é fácil/pub.in b/labs/lab03/Sobrenome não é fácil/pub.in new file mode 100644 index 0000000..b4b57b6 --- /dev/null +++ b/labs/lab03/Sobrenome não é fácil/pub.in @@ -0,0 +1,4 @@ +Ferrari +Bianchi +Hoffmann +Hofmann \ No newline at end of file diff --git a/labs/lab03/Sobrenome não é fácil/pub.out b/labs/lab03/Sobrenome não é fácil/pub.out new file mode 100644 index 0000000..7883f26 --- /dev/null +++ b/labs/lab03/Sobrenome não é fácil/pub.out @@ -0,0 +1,4 @@ +Ferrari eh facil +Bianchi nao eh facil +Hoffmann nao eh facil +Hofmann eh facil diff --git a/labs/lab03/Time de Duendes/pub.in b/labs/lab03/Time de Duendes/pub.in new file mode 100644 index 0000000..4ef7778 --- /dev/null +++ b/labs/lab03/Time de Duendes/pub.in @@ -0,0 +1,7 @@ +6 +Josh 56 +Alfred 32 +Joshua 34 +Harley 61 +Peggy 60 +Jim 25 \ No newline at end of file diff --git a/labs/lab03/Time de Duendes/pub.out b/labs/lab03/Time de Duendes/pub.out new file mode 100644 index 0000000..0e95010 --- /dev/null +++ b/labs/lab03/Time de Duendes/pub.out @@ -0,0 +1,9 @@ +Time 1 +Harley 61 +Josh 56 +Alfred 32 + +Time 2 +Peggy 60 +Joshua 34 +Jim 25 diff --git a/tps/fonte/Personagem.java b/tps/fonte/Personagem.java new file mode 100644 index 0000000..60009de --- /dev/null +++ b/tps/fonte/Personagem.java @@ -0,0 +1,177 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.text.DecimalFormat; + +public class Personagem { + + private String nome; + private int altura; + private double peso; + private String corDoCabelo; + private String corDaPele; + private String corDosOlhos; + private String anoNascimento; + private String genero; + private String homeworld; + + public String getNome() { + return nome; + } + + public void setNome(String nome) { + this.nome = nome; + } + + public int getAltura() { + return altura; + } + + public void setAltura(int altura) { + this.altura = altura; + } + + public double getPeso() { + return peso; + } + + public void setPeso(double peso) { + this.peso = peso; + } + + public String getCorDoCabelo() { + return corDoCabelo; + } + + public void setCorDoCabelo(String corDoCabelo) { + this.corDoCabelo = corDoCabelo; + } + + public String getCorDaPele() { + return corDaPele; + } + + public void setCorDaPele(String corDaPele) { + this.corDaPele = corDaPele; + } + + public String getCorDosOlhos() { + return corDosOlhos; + } + + public void setCorDosOlhos(String corDosOlhos) { + this.corDosOlhos = corDosOlhos; + } + + public String getAnoNascimento() { + return anoNascimento; + } + + public void setAnoNascimento(String anoNascimento) { + this.anoNascimento = anoNascimento; + } + + public String getGenero() { + return genero; + } + + public void setGenero(String genero) { + this.genero = genero; + } + + public String getHomeworld() { + return homeworld; + } + + public void setHomeworld(String homeworld) { + this.homeworld = homeworld; + } + + protected Personagem clone() throws CloneNotSupportedException { + Personagem novo = new Personagem(); + novo.nome = this.nome; + novo.altura = this.altura; + novo.corDoCabelo = this.corDoCabelo; + novo.corDaPele = this.corDaPele; + novo.corDosOlhos = this.corDosOlhos; + novo.anoNascimento = this.anoNascimento; + novo.genero = this.genero; + novo.homeworld = this.homeworld; + return novo; + } + + public void ler(String nomeArquivo) throws Exception { + FileReader file = new FileReader(nomeArquivo); + BufferedReader buffer = new BufferedReader(file); + String json = ""; + String line = buffer.readLine(); + while (line != null) { + json += line; + line = buffer.readLine(); + } + + buffer.close(); + file.close(); + + String temp; + temp = json.substring(json.indexOf("name") + 8); + temp = temp.substring(0, temp.indexOf("',")); + this.nome = temp; + + temp = json.substring(json.indexOf("height") + 10); + temp = temp.substring(0, temp.indexOf("',")); + if (temp.equals("unknown")) + this.altura = 0; + else + this.altura = Integer.parseInt(temp); + + temp = json.substring(json.indexOf("mass") + 8); + temp = temp.substring(0, temp.indexOf("',")); + if (temp.equals("unknown")) + this.peso = 0; + else + this.peso = Double.parseDouble(temp.replace(",", "")); + + temp = json.substring(json.indexOf("hair_color") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.corDoCabelo = temp; + + temp = json.substring(json.indexOf("skin_color") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.corDaPele = temp; + + temp = json.substring(json.indexOf("eye_color") + 13); + temp = temp.substring(0, temp.indexOf("',")); + this.corDosOlhos = temp; + + temp = json.substring(json.indexOf("birth_year") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.anoNascimento = temp; + + temp = json.substring(json.indexOf("gender") + 10); + temp = temp.substring(0, temp.indexOf("',")); + this.genero = temp; + + temp = json.substring(json.indexOf("homeworld") + 13); + temp = temp.substring(0, temp.indexOf("',")); + this.homeworld = temp; + } + + public void imprimir() { + System.out.println(toString()); + } + + public String toString() { + DecimalFormat df = new DecimalFormat("#0.##"); + String resp = " ## " + nome + " ## " + altura + " ## "; + resp += df.format(peso) + " ## " + corDoCabelo + " ## "; + resp += corDaPele + " ## " + corDosOlhos + " ## "; + resp += anoNascimento + " ## " + genero + " ## "; + resp += homeworld + " ## "; + return resp; + } + + public void imprimirNome() { + System.out.println(nome); + } + +} diff --git a/tps/gabaritos/Personagem.java b/tps/gabaritos/Personagem.java new file mode 100644 index 0000000..60009de --- /dev/null +++ b/tps/gabaritos/Personagem.java @@ -0,0 +1,177 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.text.DecimalFormat; + +public class Personagem { + + private String nome; + private int altura; + private double peso; + private String corDoCabelo; + private String corDaPele; + private String corDosOlhos; + private String anoNascimento; + private String genero; + private String homeworld; + + public String getNome() { + return nome; + } + + public void setNome(String nome) { + this.nome = nome; + } + + public int getAltura() { + return altura; + } + + public void setAltura(int altura) { + this.altura = altura; + } + + public double getPeso() { + return peso; + } + + public void setPeso(double peso) { + this.peso = peso; + } + + public String getCorDoCabelo() { + return corDoCabelo; + } + + public void setCorDoCabelo(String corDoCabelo) { + this.corDoCabelo = corDoCabelo; + } + + public String getCorDaPele() { + return corDaPele; + } + + public void setCorDaPele(String corDaPele) { + this.corDaPele = corDaPele; + } + + public String getCorDosOlhos() { + return corDosOlhos; + } + + public void setCorDosOlhos(String corDosOlhos) { + this.corDosOlhos = corDosOlhos; + } + + public String getAnoNascimento() { + return anoNascimento; + } + + public void setAnoNascimento(String anoNascimento) { + this.anoNascimento = anoNascimento; + } + + public String getGenero() { + return genero; + } + + public void setGenero(String genero) { + this.genero = genero; + } + + public String getHomeworld() { + return homeworld; + } + + public void setHomeworld(String homeworld) { + this.homeworld = homeworld; + } + + protected Personagem clone() throws CloneNotSupportedException { + Personagem novo = new Personagem(); + novo.nome = this.nome; + novo.altura = this.altura; + novo.corDoCabelo = this.corDoCabelo; + novo.corDaPele = this.corDaPele; + novo.corDosOlhos = this.corDosOlhos; + novo.anoNascimento = this.anoNascimento; + novo.genero = this.genero; + novo.homeworld = this.homeworld; + return novo; + } + + public void ler(String nomeArquivo) throws Exception { + FileReader file = new FileReader(nomeArquivo); + BufferedReader buffer = new BufferedReader(file); + String json = ""; + String line = buffer.readLine(); + while (line != null) { + json += line; + line = buffer.readLine(); + } + + buffer.close(); + file.close(); + + String temp; + temp = json.substring(json.indexOf("name") + 8); + temp = temp.substring(0, temp.indexOf("',")); + this.nome = temp; + + temp = json.substring(json.indexOf("height") + 10); + temp = temp.substring(0, temp.indexOf("',")); + if (temp.equals("unknown")) + this.altura = 0; + else + this.altura = Integer.parseInt(temp); + + temp = json.substring(json.indexOf("mass") + 8); + temp = temp.substring(0, temp.indexOf("',")); + if (temp.equals("unknown")) + this.peso = 0; + else + this.peso = Double.parseDouble(temp.replace(",", "")); + + temp = json.substring(json.indexOf("hair_color") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.corDoCabelo = temp; + + temp = json.substring(json.indexOf("skin_color") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.corDaPele = temp; + + temp = json.substring(json.indexOf("eye_color") + 13); + temp = temp.substring(0, temp.indexOf("',")); + this.corDosOlhos = temp; + + temp = json.substring(json.indexOf("birth_year") + 14); + temp = temp.substring(0, temp.indexOf("',")); + this.anoNascimento = temp; + + temp = json.substring(json.indexOf("gender") + 10); + temp = temp.substring(0, temp.indexOf("',")); + this.genero = temp; + + temp = json.substring(json.indexOf("homeworld") + 13); + temp = temp.substring(0, temp.indexOf("',")); + this.homeworld = temp; + } + + public void imprimir() { + System.out.println(toString()); + } + + public String toString() { + DecimalFormat df = new DecimalFormat("#0.##"); + String resp = " ## " + nome + " ## " + altura + " ## "; + resp += df.format(peso) + " ## " + corDoCabelo + " ## "; + resp += corDaPele + " ## " + corDosOlhos + " ## "; + resp += anoNascimento + " ## " + genero + " ## "; + resp += homeworld + " ## "; + return resp; + } + + public void imprimirNome() { + System.out.println(nome); + } + +}