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

Contenu du cours

Java Data Structures

Java Data Structures

1. Basic Data Structures
2. Additional Data Structures
3. Map
4. enum & Stream API

book
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.

java

Main

copy
123456789101112131415161718
enum CharacterClass { WARRIOR, MAGE, ARCHER, ROGUE, //write your code here } public class Main { public static void main(String[] args) { // Test the enum methods CharacterClass warrior = CharacterClass.WARRIOR; CharacterClass mage = CharacterClass.MAGE; warrior.printStats(); mage.printStats(); } }
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2
We're sorry to hear that something went wrong. What happened?
some-alt