Java';导入&x27;公用事业不工作

Java';导入&x27;公用事业不工作,java,Java,这段代码没有生成任何输出,而是在我使用“import”实用程序的行上抛出一个错误。我不知道如何删除这个错误。请帮忙!我是个新手。我在Sierra的“Head First Java”中阅读了这段代码 import java.util.*; public class DotComBust { private GameHelper helper = new GameHelper(); private ArrayList < DotCom > dotComsList = ne

这段代码没有生成任何输出,而是在我使用“import”实用程序的行上抛出一个错误。我不知道如何删除这个错误。请帮忙!我是个新手。我在Sierra的“Head First Java”中阅读了这段代码

import java.util.*;
public class DotComBust {
    private GameHelper helper = new GameHelper();
    private ArrayList < DotCom > dotComsList = new ArrayList < DotCom > ();
    private int numOfGuesses = 0;
    private void setUpGame() {
        DotCom one = new DotCom();
        one.setName("pets.com");
        DotCom two = new DotCom();
        two.setName("toys.com");
        DotCom three = new DotCom();
        three.setName("go.com");
        dotComsList.add(one);
        dotComsList.add(two);
        dotComsList.add(three);
        System.out.println("sink all coms");
        System.out.println("jk yhhg  jyhhj ");
        System.out.println("in small no of guesses");
        for (DotCom dotComToSet: dotComsList) {
            ArrayList < String > newLoction = helper.placeDotCom(3);
            dotComToSet.setLocationCells(newLocation);

        }
    }
    private void stratPlaying() {
        while (!dotComsList.isEmpty()) {
            String userGuess = helper.getUserInput("enter a number");
            checkUserGuess(userGuess);

        }
        finishGame();

    }
    private void checkUserGuess(String userGuess) {
        numOfGuesses++;
        String result = "miss";
        for (DotCom dotComToTest: dotComsList) {
            result = dotComToTest.checkYourself(userGuess);
            if (result.equals("hit")) {
                break;
            }
            if (result.equals("kill")) {
                dotComsList.remove(dotComToTest);
                break;
            }
        }
        System.out.println(result);
    }
    private void finishGame() {

        System.out.println("all d are dead");

        if (numOfGuesses <= 18) {
            System.out.println("you took " + numOfGuesses);
            System.out.println("u got out");
        } else {
            System.out.println("took u long " + numOfGuesses);
            System.out.println("u are worst");
        }
    }
    public static void main(String[] args) {
        DotComBust game = new DotComBust();
        game.setUpGame();
        game.startPlaying();
    }
}
import java.util.*;
public class DotCom {
    private ArrayList < String > locationCells;
    private String name;
    public void setLocationCells(ArrayList < String > loc) {
        locationCells = loc;
    }
    public void setName(String n) {
        name = n;
    }
    public String checkYourself(String userInput) {
        String result = "miss";
        int index = locationCells.indexOf(userInput);
        if (index <= 0) {
            locationCells.remove(index);
            if (locationCells.isEmpty()) {
                result = "kill";
                System.out.println("you sunk " + name);
            } else {
                result = "hit";
            }
        }
        return result;
    }
}
import java.util.*;
公共类dot{
私有GameHelper helper=新GameHelper();
私有ArrayListdotComsList=新ArrayList();
private int numOfGuesses=0;
私人游戏(){
DotCom one=新的DotCom();
一个.setName(“pets.com”);
dotcomtwo=新的DotCom();
2.setName(“toys.com”);
DotCom三=新的DotCom();
三、setName(“go.com”);
添加(一个);
添加(两个);
添加(三个);
System.out.println(“接收所有通信”);
System.out.println(“jk-yhg-jyhj”);
System.out.println(“小范围的猜测”);
for(DotCom dotComToSet:dotComsList){
ArrayListnewLoction=helper.placeDotCom(3);
dotComToSet.setLocationCells(新位置);
}
}
私人游戏{
而(!dotComsList.isEmpty()){
字符串userGuess=helper.getUserInput(“输入一个数字”);
checkUserGuess(userGuess);
}
finishGame();
}
私有void checkUserGuess(字符串userGuess){
numOfGuesses++;
字符串result=“miss”;
for(DotCom dotComToTest:dotComsList){
结果=dotComToTest.checkYourself(userGuess);
如果(结果等于(“命中”)){
打破
}
if(result.equals(“kill”)){
dotComsList.remove(dotComToTest);
打破
}
}
系统输出打印项次(结果);
}
私有void finishGame(){
System.out.println(“所有d都死了”);
if(numof)猜测位置单元格;
私有字符串名称;
公共void setLocationCells(ArrayListloc){
locationCells=loc;
}
公共void集合名(字符串n){
name=n;
}
公共字符串checkYourself(字符串用户输入){
字符串result=“miss”;
int index=locationCells.indexOf(userInput);

如果(index您不应该将所有内容都放在一个文件中。请创建一个新文件,
DotCom
并将代码粘贴到下面

import java.util.*;
public class DotCom {
    private ArrayList < String > locationCells;
    private String name;
    public void setLocationCells(ArrayList < String > loc) {
        locationCells = loc;
    }
    public void setName(String n) {
        name = n;
    }
    public String checkYourself(String userInput) {
        String result = "miss";
        int index = locationCells.indexOf(userInput);
        if (index <= 0) {
            locationCells.remove(index);
            if (locationCells.isEmpty()) {
                result = "kill";
                System.out.println("you sunk " + name);
            } else {
                result = "hit";
            }
        }
        return result;
    }
}
import java.util.*;
公共类网络公司{
私有ArrayListlocationCells;
私有字符串名称;
公共void setLocationCells(ArrayListloc){
locationCells=loc;
}
公共void集合名(字符串n){
name=n;
}
公共字符串checkYourself(字符串用户输入){
字符串result=“miss”;
int index=locationCells.indexOf(userInput);

如果(索引您遇到了什么错误?另外,请正确缩进代码。您是否将所有内容都放在同一个文件中?DotCombum.java:90:error:class、interface或enum预期导入java.util.*;^1 error@khelwoodd为什么在同一个文件中有两个相同包的导入?为什么其中一个处于中间位置文件中的DLE?您得到的错误是因为您有一个导入代码>文件中的java java. UTI.*;< /C> >,在两个类声明之间。不允许。您应该将两个类分开为两个文件,并且可能保留<代码>主()。
方法也在它自己的单独类中。@DakshBhayana作为Java初学者,你应该一步一步地学习这门语言。通过一步一步地学习,你将深入理解这门语言!你会得到帮助。我们会给你一些提示,但不会给你全部代码。祝你好运!