Java方法未传递给main

时间:2018-09-20 02:56:24

标签: java

所以,我似乎在通过所有三种方法时遇到问题

机器玩一个

机器玩两个

机器扮演三个角色

进入主要功能,以便那些if语句激活并开始计数/工作。我知道要打印我需要使用的方法

System.out.println(displayMachineOne());

但是我只是想让那些if语句在主目录中起作用,所以使主计数器起作用。

如果需要使用上下文,则是:目的是计算一下维奇要花多长时间才能按1-2-3-1-2-3-1等顺序玩可预测的老虎机。

现在它只运行了100次循环(因为有100个硬币),然后她就没赢过钱就破产了。

我也很确定我也需要返回季度总数,但是首先我想尝试使方法正确通过。

感谢您的帮助。 (是的,我确实尝试过Google,但似乎找不到我想要的东西)

public class WinningBig {

    public static void main(String[] args) {
        int totalQuarters = 100;
        int totalPlays = 0;
        int machineOnePlays = 0;
        int machineTwoPlays = 0;
        int machineThreePlays = 0;

        while(true)
        {
            if(totalQuarters > 0) {
                totalQuarters = displayMachineOne(totalQuarters, machineOnePlays);
                machineOnePlays ++;
                totalPlays ++;
                totalQuarters--;

            }
            if(totalQuarters > 0) {
            totalQuarters = displayMachineTwo(totalQuarters, machineTwoPlays);
            machineTwoPlays++;
            totalPlays++;
            totalQuarters--;
            }
            if(totalQuarters > 0) {
                totalQuarters = displayMachineThree(totalQuarters, machineThreePlays);
                machineThreePlays++;
                totalPlays++;
                totalQuarters--;
                }else {
            System.out.println("Vickie lost all of her money! it took    " +
                    totalPlays + " plays for her to go broke");
            return;
        }
        }
    }

    public static int displayMachineOne(int totalQuarters,
                                           int machineOnePlays) {
         machineOnePlays++;

        if(machineOnePlays == 35) {

            totalQuarters += 25;
            machineOnePlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 25 quarters, her total is now " + (totalQuarters) * .25);

        }
        return totalQuarters;

    }

    public static int displayMachineTwo(int totalQuarters,
                                           int machineTwoPlays) {
            machineTwoPlays++;

        if(machineTwoPlays == 100) {

            totalQuarters += 75;
            machineTwoPlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 75 quarters, her total is now " + (totalQuarters) * .25);

        }
        return totalQuarters;
    }
    public static int displayMachineThree(int
            totalQuarters,int machineThreePlays) {

            machineThreePlays++;
        if(machineThreePlays == 8) {
            totalQuarters += 5;
            machineThreePlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 5 quarters, her total is now " + (totalQuarters) * .25);

        }
        return totalQuarters;

    }
}

1 个答案:

答案 0 :(得分:-1)

public class WinningBig {
    static int totalQuarters = 100;
    static int totalPlays = 0;
    static int machineOnePlays = 0;
    static int machineTwoPlays = 0;
    static int machineThreePlays = 0;

    public static void main(String[] args) {
        while (true) {
            if (totalQuarters > 0) {
                displayMachineOne();
                machineOnePlays++;
                totalPlays++;
                totalQuarters--;

            }
            if (totalQuarters > 0) {
                displayMachineTwo();
                machineTwoPlays++;
                totalPlays++;
                totalQuarters--;
            }
            if (totalQuarters > 0) {
                displayMachineThree();
                machineThreePlays++;
                totalPlays++;
                totalQuarters--;
            } else {
                System.out.println("Vickie lost all of her money! it took    " +
                        totalPlays + " plays for her to go broke");
                return;
            }
        }
    }

    public static void displayMachineOne() {

        if (machineOnePlays == 35) {

            totalQuarters += 25;
            machineOnePlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 25 quarters, her total is now " + (totalQuarters - 1) * .25);

        }

    }

    public static void displayMachineTwo() {


        if (machineTwoPlays == 100) {

            totalQuarters += 75;
            machineTwoPlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 75 quarters, her total is now " + (totalQuarters - 1) * .25);

        }
    }

    public static void displayMachineThree() {


        if (machineThreePlays == 8) {
            totalQuarters += 5;
            machineThreePlays = 0;

            System.out.println("Vickie won on Machine One in the amount of 5 quarters, her total is now " + (totalQuarters - 1) * .25);

        }
    }
}