-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feitas as instruções relacionadas aos fields.
- Loading branch information
Showing
21 changed files
with
391 additions
and
58 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class Pessoa { | ||
|
||
private String nome; | ||
private int idade; | ||
public double[] moedas = new double[]{0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0}; | ||
public static String nacionalidade = "valor padrao"; | ||
|
||
public Pessoa() { | ||
this.nome = "anonimo"; | ||
} | ||
|
||
public Pessoa(String nome, int idade) { | ||
this.setNome(nome); | ||
this.setIdade(idade); | ||
} | ||
|
||
void realizarCompra(double valor) { | ||
double total = 0.0; | ||
for (double d : this.moedas) { | ||
total += d; | ||
} | ||
if (total < valor) { | ||
System.out.println("Pse man... vai ficar sem"); | ||
return; | ||
} | ||
System.out.println("Transação aprovada"); | ||
} | ||
|
||
void setNome(String nome) { | ||
this.nome = nome; | ||
} | ||
|
||
String getNome() { | ||
return this.nome; | ||
} | ||
|
||
void setIdade(int idade) { | ||
if (idade <= 0) { | ||
System.out.println("Vc tem idade negativa seu arrombado???"); | ||
// depois por pra lançar exceção | ||
return; | ||
} else { | ||
this.idade = idade; | ||
} | ||
} | ||
|
||
int getIdade() { | ||
return this.idade; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class ClassTest { | ||
public static void main(String[] args) { | ||
Numerais nums = new Numerais(); | ||
System.out.println("Field Numerais.d = " + nums.d); | ||
|
||
int um_mais_um_pouco = nums.getUm() + 357; | ||
// o javac n compila se for privado... | ||
// System.out.println("Nums.str = " + nums.str); | ||
um_mais_um_pouco++; | ||
System.out.println("somando com local var = " + um_mais_um_pouco); | ||
System.out.println("construtor custom = " + new Numerais(200).getUm()); | ||
|
||
Numerais num2 = new Numerais(); | ||
num2.setInteger(86451); | ||
System.out.println("set = " + num2.getUm()); | ||
|
||
Pessoa p = new Pessoa(); | ||
System.out.println("pessoa linda de nome = " + p.getNome()); | ||
p.setNome("joão Kleber"); | ||
System.out.println("pessoa linda de nome = " + p.getNome()); | ||
|
||
System.out.println("nacionalidade da pessoa linda = " + p.nacionalidade); | ||
p.nacionalidade = "Canadense"; | ||
System.out.println("nacionalidade da pessoa linda depois de fazer o passaporte = " + p.nacionalidade); | ||
|
||
System.out.println("indo pro xops comprar pastel KKK"); | ||
p.realizarCompra(5.50); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef INCLUDE_UTILS_CLASS_T_H_ | ||
#define INCLUDE_UTILS_CLASS_T_H_ | ||
|
||
#include <map> | ||
#include "utils/external/any.h" | ||
#include "utils/field_t.h" | ||
#include "utils/object.h" | ||
|
||
namespace Utils { | ||
struct Class_t { | ||
Class_t() = default; | ||
|
||
Class_t(const std::string &class_name) { this->class_name = class_name; } | ||
|
||
void addField(const Any &val, const std::string &field_name, | ||
const std::string &descriptor) { | ||
auto f = Field_t(val); | ||
if (!descriptor.compare("java/lang/String") || | ||
!descriptor.compare("java/lang/Object")) { | ||
f.data = new Object(val); | ||
} | ||
this->fields[field_name] = f; | ||
} | ||
|
||
Field_t &getField(const std::string &field_name) { | ||
return this->fields[field_name]; | ||
} | ||
|
||
std::string class_name; | ||
std::map<std::string, Field_t> fields; | ||
}; | ||
} // namespace Utils | ||
|
||
#endif // INCLUDE_UTILS_CLASS_T_H_ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef INCLUDE_UTILS_FIELD_T_H_ | ||
#define INCLUDE_UTILS_FIELD_T_H_ | ||
|
||
#include "utils/array_t.h" | ||
#include "utils/external/any.h" | ||
|
||
namespace Utils { | ||
struct Field_t { | ||
Field_t() = default; | ||
|
||
Field_t(Any v) { this->data = v; } | ||
|
||
~Field_t() { | ||
if (this->data.is<Array_t *>()) { | ||
delete this->data.as<Array_t *>(); | ||
} | ||
} | ||
|
||
Any data; | ||
}; | ||
} // namespace Utils | ||
|
||
#endif // INCLUDE_UTILS_FIELD_T_H_ |
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
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
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
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
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
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
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
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
Oops, something went wrong.