"表达预期"和"找不到符号"错误

时间:2014-05-08 03:17:29

标签: java

我最近在java中学习了一些OOP课程。在今天实施它时,我遇到了#34;找不到符号"我的程序错误。在旁边的建议中,它表示"表达预期"。我一直试图找出我的错误一段时间但到目前为止还没有遇到我的运气。有人可以帮我吗?

这是我的主要课程:

public class Slotmachine {

    public static void main(String[] args) {

        int plays;

        SlotMac machine[] = new SlotMac[3];    
                                                 // error seems to be somewhere here!
        SlotMac[0] = new SlotMac(3,35,30);    
        SlotMac[1] = new SlotMac(10,100,60);
        SlotMac[2] = new SlotMac(4,10,9);

        plays = machine.firstmachine(machine[0]);
    }
}

我的另一堂课:

public class SlotMac {

    int win_plays;
    int times_played;
    int quarters;

    public SlotMac(int times_played, int win_plays, int quarters) {
        this.win_plays = win_plays;
        this.times_played = times_played;
        this.quarters = quarters;
    }

    public int firstmachine(SlotMac one) {
        return plays;
    }
}

java:找不到符号   符号:类SlotMac   位置:类Slotmachine

相同的错误束时间。

5 个答案:

答案 0 :(得分:2)

您应该使用数组的变量名而不是classname。

machine[0] = new SlotMac(3,35,30);    
machine[1] = new SlotMac(10,100,60);
machine[2] = new SlotMac(4,10,9);

我看到你修复了其他firsmachine()相关内容

答案 1 :(得分:0)

您正在创建一系列机器,因此请更改

SlotMac[0] = new SlotMac(3,35,30);    
SlotMac[1] = new SlotMac(10,100,60);
SlotMac[2] = new SlotMac(4,10,9);

machine[0] = new SlotMac(3,35,30);    
    machine[1] = new SlotMac(10,100,60);
    machine[2] = new SlotMac(4,10,9);

答案 2 :(得分:0)

而不是SLotMac[0],它应该是machine[0],依此类推......

我不理解你的评论。但这是一个示例代码

public static void main(String [] args){

int plays;

SlotMac machine[] = new SlotMac[3];    
                                         // error seems to be somewhere here!
machine[0] = new SlotMac(3,35,30);    
machine[1] = new SlotMac(10,100,60);
machine[2] = new SlotMac(4,10,9);

plays= machine[0].firstmachine(machine[0]);
}

答案 3 :(得分:0)

将其更改为:

    SlotMac[0] = new SlotMac(3,35,30);    
    SlotMac[1] = new SlotMac(10,100,60);
    SlotMac[2] = new SlotMac(4,10,9);

这样:

machine[0] = new SlotMac(3,35,30);    
machine[1] = new SlotMac(10,100,60);
machine[2] = new SlotMac(4,10,9);

答案 4 :(得分:0)

你导入了同一个类吗?

在代码

中使用之前,您需要导入该类

所以使用import语句

导入它

import package.name.SlotMac进入SlotMachine.java档案