gpt4 book ai didi

Java 方法未传递到 main

转载 作者:行者123 更新时间:2023-12-01 06:03:07 27 4
gpt4 key购买 nike

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

机器播放一个

机器玩两个

机器玩三

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

System.out.println(displayMachineOne());

但我只是想让这些 if 语句在 main 中工作,以便让主计数器工作。

如果需要上下文:目标是计算 vicie 按 1-2-3-1-2-3-1 等顺序玩可预测的老虎机需要多长时间才能破产。

现在它只运行循环 100 次(因为有 100 个硬币),然后她就破产了,从未赢得过任何东西。

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

感谢任何帮助。 (是的,我确实尝试过谷歌,但我似乎找不到我要找的东西)

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;

}
}

最佳答案

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);

}
}
}

关于Java 方法未传递到 main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52416894/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com