1+ public class Personagem {
2+
3+ private String nome ;
4+ private int energia = 10 ;
5+ private int fome = 0 ;
6+ private int sono = 0 ;
7+ final static int LIMITE_SUPERIOR = 10 ;
8+
9+ public Personagem (int energia , int fome , int sono ) {
10+ if (energia >= 0 && energia <= 10 )
11+ this .energia = energia ;
12+ if (fome >= 0 && fome <= 10 )
13+ this .fome = fome ;
14+ if (sono >= 0 && sono <= 10 )
15+ this .sono = sono ;
16+ }
17+
18+ public Personagem (String nome , int energia , int fome , int sono ) {
19+ this (energia , fome , sono );
20+ this .nome = nome ;
21+ }
22+
23+ public void setNome (String nome ) {
24+ this .nome = nome ;
25+ }
26+
27+ public String getNome () {
28+ return this .nome ;
29+ }
30+
31+ public int getEnergia () {
32+ return this .energia ;
33+ }
34+
35+ public int getFome () {
36+ return this .fome ;
37+ }
38+
39+ public int getSono () {
40+ return this .sono ;
41+ }
42+
43+ void cacar () {
44+ if (this .energia >= 2 ) {
45+ System .out .printf ("%s caçando...\n " , nome );
46+ this .energia = this .energia - 2 ;
47+ } else {
48+ System .out .printf ("%s sem energia para caçar...\n " , nome );
49+ }
50+ this .fome = Math .min (this .fome + 1 , LIMITE_SUPERIOR );
51+ this .sono = Math .min (this .sono + 1 , LIMITE_SUPERIOR );
52+ }
53+
54+ void comer () {
55+ if (this .fome >= 1 ) {
56+ System .out .printf ("%s comendo...\n " , nome );
57+ this .fome -= 1 ;
58+ this .energia = this .energia + 1 <= LIMITE_SUPERIOR ? this .energia + 1 : this .energia ;
59+ } else {
60+ System .out .printf ("%s sem fome...\n " , nome );
61+ }
62+ }
63+
64+ void dormir () {
65+ if (this .sono >= 1 ) {
66+ System .out .printf ("%s dormindo...\n " , nome );
67+ this .sono -= 1 ;
68+ this .energia = this .energia + 1 <= LIMITE_SUPERIOR ? this .energia + 1 : this .energia ;
69+ } else {
70+ System .out .printf ("%s sem sono...\n " , nome );
71+ }
72+ }
73+
74+ void estado () {
75+ System .out .println ("\n -------------------------------------------------" );
76+ System .out .printf ("ESTADO:\n Personagem: %s\n Energia: %d\n Fome: %d\n Sono: %d" , this .getNome (), this .getEnergia (), this .getFome (), this .getSono ());
77+ }
78+ }
0 commit comments