Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge (Character Class) | enum & Stream API
Java Data Structures

Challenge (Character Class)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 the printStats() method. Since printStats() 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.

java

main.java

  • Define an enum called CharacterClass with different character classes (e.g., Warrior, Mage) and their attributes (e.g., hp, atk).
  • Include a constructor in the enum to initialize the attributes for each character class.
  • Implement a method printStats() within the enum to print the statistics of the character, including class name, health points (hp), and attack points (atk).
  • In the main program, create instances of character classes and call the printStats() method to display their statistics.
  • Все було зрозуміло?

    Секція 4. Розділ 2
    course content

    Зміст курсу

    Java Data Structures

    Challenge (Character Class)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 the printStats() method. Since printStats() 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.

    java

    main.java

  • Define an enum called CharacterClass with different character classes (e.g., Warrior, Mage) and their attributes (e.g., hp, atk).
  • Include a constructor in the enum to initialize the attributes for each character class.
  • Implement a method printStats() within the enum to print the statistics of the character, including class name, health points (hp), and attack points (atk).
  • In the main program, create instances of character classes and call the printStats() method to display their statistics.
  • Все було зрозуміло?

    Секція 4. Розділ 2
    some-alt