From 74a696b0baf1892765bad050cb209d588f204c3c Mon Sep 17 00:00:00 2001 From: Felipe Domingos Date: Tue, 21 Mar 2023 22:59:53 -0300 Subject: [PATCH] gabarito --- tps/fonte/Personagem.java | 177 ++++++++++++++++++++++++++++++++++ tps/gabaritos/Personagem.java | 177 ++++++++++++++++++++++++++++++++++ 2 files changed, 354 insertions(+) create mode 100644 tps/fonte/Personagem.java create mode 100644 tps/gabaritos/Personagem.java 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); + } + +}