import java.util.Scanner; // Define a class named Character class Character { private String name; // Attribute to hold the character's name private String classType; // Attribute to hold the character's class type private int level; // Attribute to hold the character's level // Constructor to initialize the character's attributes public Character(String name, String classType, int level) { if (name.isEmpty()) { throw new IllegalArgumentException("Name cannot be empty."); } if (!(classType.equals("warrior") || classType.equals("mage"))) { throw new IllegalArgumentException("Invalid class type. Must be 'warrior' or 'mage'."); } if (level < 1 || level > 100) { throw new IllegalArgumentException("Level must be between 1 and 100."); } this.name = name; this.classType = classType; this.level = level; } // Display character information public void displayCharacter() { System.out.println("Character created:"); System.out.println("Name: " + name); System.out.println("Class Type: " + classType); System.out.println("Level: " + level); } } // Main class to handle character creation public class MainCharacterCreation { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { // Prompt the user for character details System.out.print("Enter character name: "); String name = scanner.nextLine(); System.out.print("Enter character class (warrior/mage): "); String classType = scanner.nextLine(); System.out.print("Enter character level (1-100): "); int level = scanner.nextInt(); // Create a new Character object with user input Character character = new Character(name, classType, level); // Display the character details character.displayCharacter(); } catch (IllegalArgumentException e) { // Catch and print the error message if an exception occurs System.out.println("Error: " + e.getMessage()); } finally { scanner.close(); // Close the scanner } } }