我正在尝试从以下行开始编译一些代码:
import java.util.*;
我不断收到错误:
class, interface, or enum expected
我在其他帖子上看到这是因为我没有正确使用导入。我是否需要以某种方式进行设置,例如当我首先为 java 添加 PATH 异常时。我很难弄清楚这一点。我很确定代码除此之外还不错。
import java.util.*;
public class setUpGame {
private ArrayList<Weapon> weaponArray = new ArrayList<Weapon>();
class Weapon{
private String name = null;
private String description = null;
private int damageBase;
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
public String getDescription(){
return description;
}
public void setDescription(String d){
description = d;
}
public int getDamageBase(){
return damageBase;
}
public void setDamageBase(int d){
damageBase = d;
}
}//END class Weapon
Weapon spear = new Weapon();
spear.setName("Mighty Spear");
spear.setDescription("An ancient spear. Bronze of tip, ash of shaft, decorated in slivers or roc's feather.");
spear.setDamageBase(3);
Weapon hooks = new Weapon();
hooks.setName("Silver Hooks");
hooks.setDescription("A pair of sharp, hand-held fighting hooks. Obsidian core, plated in silver.");
hooks.setDamageBase(2);
Weapon flameSword = new Weapon();
sword.setName("Flamesake");
sword.setDescription("An arming sword, newly enchanted. It erupts in flame when removed from the scabbard.");
sword.setDamageBase(3);
Weapon scissors = new Weapon();
scissors.setName("Snippy");
scissors.setDescription("Your mother's sewing scissors. They are nearly two hands long, as she was a large woman.");
scissors.setDamageBase(1);
Weapon darkGun = new Weapon();
darkGun.setName("Dark Cannon");
darkGun.setDescription("A finely crafted hand cannon. It has been enchanted by a dark sorcerer to fire bolts of corrupting darkness.");
darkGun.setDamageBase(3);
Weapon iceBow = new Weapon();
iceBow.setName("Chilling Bow");
iceBow.setDescription("");
iceBow.setDamageBase(2);
weaponArray.add(spear);
weaponArray.add(hooks);
weaponArray.add(flameSword);
weaponArray.add(scissors);
weaponArray.add(darkGun);
weaponArray.add(iceBow);
// set up game flavor text
}
public class SetUpGameTestDrive(){
public static void main(String [] args){
for (Weapon currentWeapon : weaponArray){
System.out.println(currentWeapon.getName() + "is " + currentWeapon.getDescription() + "It has a damage base of " +
currentWeapon.getDamageBase() + ".");
}
}
}