Conteúdo do Curso
Java Data Structures
2. Additional Data Structures
Java Data Structures
Challenge (Character Class)
Task
Create a Java program that uses an enum
called CharacterClass
to represent different character classes in a game. Each character class should have associated attributes such as health points (hp
) and attack points (atk
). Implement a method printStats()
that prints the statistics of the character.
Note
The
this
keyword is used to refer to the current instance of the enum (character class) within theprintStats()
method. SinceprintStats()
is an instance method, it operates on a specific instance of the enum. Using this clarifies that the attributes being accessed are specific to the current enum instance.
main.java
CharacterClass
with different character classes (e.g., Warrior, Mage) and their attributes (e.g., hp, atk).printStats()
within the enum to print the statistics of the character, including class name, health points (hp), and attack points (atk).printStats()
method to display their statistics.Tudo estava claro?
Conteúdo do Curso
Java Data Structures
2. Additional Data Structures
Java Data Structures
Challenge (Character Class)
Task
Create a Java program that uses an enum
called CharacterClass
to represent different character classes in a game. Each character class should have associated attributes such as health points (hp
) and attack points (atk
). Implement a method printStats()
that prints the statistics of the character.
Note
The
this
keyword is used to refer to the current instance of the enum (character class) within theprintStats()
method. SinceprintStats()
is an instance method, it operates on a specific instance of the enum. Using this clarifies that the attributes being accessed are specific to the current enum instance.
main.java
CharacterClass
with different character classes (e.g., Warrior, Mage) and their attributes (e.g., hp, atk).printStats()
within the enum to print the statistics of the character, including class name, health points (hp), and attack points (atk).printStats()
method to display their statistics.Tudo estava claro?