Java 将字符统计信息打印到控制台

Java 将字符统计信息打印到控制台,java,interface,Java,Interface,据我所知,这就是我试图做的, 我正在创建一个界面来概括角色是什么 我正在创建一个类来定义角色将使用的每个方法。 在同一个类中,我根据自己的喜好多次创建该角色的新对象 所以,如果我想制作10个字符,我只需要在同一个类中制作 目前我正试图通过赋予角色属性来创建一个角色 然后我想System.out.prinln但是当我编译时 javac Hero.java Hero.java:3: error: interface expected here public class Hero implements

据我所知,这就是我试图做的, 我正在创建一个界面来概括角色是什么

我正在创建一个类来定义角色将使用的每个方法。
在同一个类中,我根据自己的喜好多次创建该角色的新对象

所以,如果我想制作10个字符,我只需要在同一个类中制作

目前我正试图通过赋予角色属性来创建一个角色

然后我想
System.out.prinln
但是当我编译时

javac Hero.java
Hero.java:3: error: interface expected here
public class Hero implements Character {
                             ^
1 error
我把
角色改成了玩家
,这就是我得到的

javac Hero.java Hero.java:3: error: cannot find symbol public class Hero implements Player {                              ^   symbol: class Player 1 error
2个文件
字符界面
英雄类
公共接口字符{

        // define methods that must be defined across all character types
        int getLevel();
        String getPrimaryAttribute();
        String getAttackType();
        String getAbility1();
        String getAbility2();
        String getAbility3();
        String getAbility4();
        double getStrength();
        double getStrengthMultiplier();
        double getAgility();
        double getAgilityMultiplier();
        double getIntelligence();
        double getIntelligenceMultiplier();
        int getHealth();
        int getMana();
        int getDamageMin();
        int getDamageMax();
        int getRange();
        double getArmor();
        int getMovement();

    }

public class Hero implements Character {

        private int level;
        private String primaryAttribute;
        private String attackType;
        private String ability1;
        private String ability2;
        private String ability3;
        private String ability4;
        private double strength;
        private double strengthMultiplier;
        private double agility;
        private double agilityMultiplier;
        private double intelligence;
        private double intelligenceMultiplier;
        private int health;
        private int mana;
        private int damageMin;
        private int damageMax;
        private int range;
        private double armor;
        private int movement;

        //default constructor
        public Hero(
                int level,
                String primaryAttribute,
                String attackType,
                String ability1,
                String ability2,
                String ability3,
                String ability4,
                double strength,
                double strengthMultiplier,
                double agility,
                double agilityMultiplier,
                double intelligence,
                double intelligenceMultiplier,
                int health,
                int mana,
                int damageMin,
                int damageMax,
                int range,
                double armor,
                int movement
                    ) {

        } // End Constructor

        public static void main (String[] args) {
            DrowRanger();

            }

        private static Object DrowRanger() {
        Hero DrowRanger = new Hero(
              0,
              "Agility",
              "Ranged",
              "Frost Arrows",
              "Gust",
              "Precision Aura",
              "Marksmanship",
              17,
              1.9,
              26,
              1.9,
              15,
              1.4,
              473,
              195,
              44,
              55,
              625,
              0.64,
              300);

        System.out.println(DrowRanger);
        return DrowRanger();
}


        // getters and setters - required to implement ALL from interface
        public int getLevel() {
            return this.level;
        }

        public String getPrimaryAttribute() {
            return this.primaryAttribute;
        }

        public String getAttackType() {
            return this.attackType;
        }

        public String getAbility1() {
            return this.ability1;
        }

        public String getAbility2() {
            return this.ability2;
        }

        public String getAbility3() {
            return this.ability3;
        }

        public String getAbility4() {
            return this.ability4;
        }

        public double getStrength() {
            return this.strength;
        }

        public double getStrengthMultiplier() {
            return this.strengthMultiplier;
        }

        public double getAgility() {
            return this.agility;
        }

        public double getAgilityMultiplier() {
            return this.agilityMultiplier;
        }

        public double getIntelligence() {
            return this.intelligence;
        }

        public double getIntelligenceMultiplier() {
            return this.intelligenceMultiplier;
        }

        public int getHealth() {
            return this.health;
        }

        public int getMana() {
            return this.mana;
        }

        public int getDamageMin() {
            return this.damageMin;
        }

        public int getDamageMax() {
            return this.damageMax;
        }

        public int getRange() {
            return this.range;
        }

        public double getArmor() {
            return this.armor;
        }

        public int getMovement() {
            return this.movement;
        }

    // This is where the setters are.

        public void setLevel(int level) {
            this.level = level;
        }

        public void setPrimaryAttribute(String primaryAttribute) {
            this.primaryAttribute = primaryAttribute;
        }

        public void setAttackType(String attackType) {
            this.attackType = attackType;
        }

        public void setAbility1(String ability1) {
            this.ability1 = ability1;
        }

        public void setAbility2(String ability2) {
            this.ability2 = ability2;
        }

        public void setAbility3String(String ability3) {
            this.ability3 = ability3;
        }

        public void setAbility4(String ability4) {
            this.ability4 = ability4;
        }

        public void setStrength(double strength) {
            this.strength = strength;
        }

        public void setStrengthMultiplier(double strengthMultiplier) {
            this.strengthMultiplier = strengthMultiplier;
        }

        public void setAgility(double agility) {
            this.agility = agility;
        }

        public void setAgilityMultiplier(double agilityMultiplier) {
            this.agilityMultiplier = agilityMultiplier;
        }

        public void setIntelligence(double intelligence) {
            this.intelligence = intelligence;
        }

        public void setIntelligenceMultiplier(double intelligenceMultiplier) {
            this.intelligenceMultiplier = intelligenceMultiplier;
        }

        public void setHealth(int health) {
            this.health = health;
        }

        public void setMana(int mana) {
            this.mana = mana;
        }

        public void setDamageMin(int damageMin) {
            this.damageMin = damageMin;
        }

        public void setDamageMax(int damageMax) {
            this.damageMax = damageMax;
        }

        public void setRange(int range) {
            this.range = range;
        }

        public void setArmor(double armor) {
            this.armor = armor;
        }

        public void setMovement(int movement) {
            this.movement = movement;
        }

    } // End Character Class

Java已经定义了一个字符类(在Java.lang包中)

Character类将原语类型char的值包装在对象中。Character类型的对象包含一个类型为char的字段


编辑-默认情况下会导入此包
java.lang
,因此接口名称与此包中定义的
Character
类冲突。因此,这就是问题所在。无论如何,最好避免使用完全相同的名称。

java已经定义了一个Character类(在包java.lang中)

Character类将原语类型char的值包装在对象中。Character类型的对象包含一个类型为char的字段


编辑-默认情况下会导入此包
java.lang
,因此接口名称与此包中定义的
Character
类冲突。因此,这就是问题所在。无论如何,最好避免使用完全相同的名称。

这不是完整答案。您需要解释
Character
在和中的包类中始终包含
java.lang
。任何导致名称冲突的情况。@NichoDiaz,否-答案是正确的,但不完整。哦,那么你说的错误是我命名了接口角色?@Boristespider我添加了你提到的部分。谢谢。我将角色更改为Player,这就是我得到的,
javac Hero.java Hero.java:3:错误:找不到符号公共类{^symbol:class Player 1错误
这不是完整的答案。您需要解释
字符
所在的包以及
java.lang
始终包含在类中。这会导致名称冲突的任何错误。@NichoDiaz,不-答案是正确的,但不完整。哦,您说的错误不是我给接口角色命名了什么?@BoristheSpider我添加了你提到的部分。谢谢。我将角色改为Player,这就是我得到的,
javac Hero.java Hero.java:3:错误:找不到符号公共类Hero实现了Player{^symbol:class Player 1 error
当您就此主题提出第一个问题时,在我的示例中,我使用了名称CharacterType而不是Character作为基类。现在您知道为什么了。啊,对了,谢谢。当您就此主题提出第一个问题时,我在我的示例中使用了名称CharacterType而不是Character现在你知道为什么了,对了,谢谢。