Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can someone help me find the error in my program? When I compile it, it gives the cannot find symbol error. I have been playing around with it for a while but cant seem to grasp my mistake.

My main class:

public static void main(String[] args) {

    int plays;

    SlotMac machine[] = new SlotMac[3];

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

    plays= firstmachine(machine[0]);
    System.out.println(plays);

My other class:

public class SlotMac {

    int win_plays, 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() {
        return plays;
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

there is no method firstmachine(SlotMac obj)

so when you say firstmachine(machine[0]); it will try to search the same method in the same class, which it will not find.

you need to call the method like following

machine[0].firstmachine();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...