次の行で始まるコードをコンパイルしようとしています。
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() + ".");
}
}
}