简体   繁体   English

带有 if else 语句的简单 Java 老虎机 [关闭]

[英]Simple Java slots machine with if else statements [closed]

I have the following information on how the problem must be structured: Write an application that simulates a gambling slot machine.我有以下关于如何构造问题的信息: 编写一个模拟老虎机的应用程序。 In the application, perform the following tasks:在应用程序中,执行以下任务:

  1. Prompt the player to enter the amount of money that the player is willing to gamble.提示玩家输入玩家愿意赌博的金额。
  2. Create three random numbers in range from one to four to represent three of the following four objects (Apple, Orange, Cherry and Pineapple).在 1 到 4 的范围内创建三个随机数来表示以下四个对象中的三个(Apple、Orange、Cherry 和 Pineapple)。
  3. Compare the numbers for equality and calculates the prize.比较数字是否相等并计算奖金。 o If all three numbers are the same, the player wins three times the amount inserted. o 如果所有三个数字相同,则玩家将赢得三倍的投注金额。 o If two objects are the same the player wins back the amount inserted (gets the money back), otherwise the player wins $0. o 如果两个对象相同,则玩家赢回插入的金额(拿回钱),否则玩家赢 0 美元。
  4. Display the randomly selected objects (fruits names, not integers).显示随机选择的对象(水果名称,而不是整数)。 Use switch or if else statements to examine the randomly created integers in order to display the corresponding fruits.使用 switch 或 if else 语句检查随机创建的整数以显示相应的结果。
  5. Display the dollar amount that the player wins.显示玩家赢得的美元金额。
  6. Here is an example what the program should do:这是程序应该做什么的示例:

Enter the dollar amount inserted into the slot machine: 100输入投入老虎机的美元金额:100

Orange Apple Cherry橙苹果樱桃

Sorry, you lost对不起,你输了

Or或者

Enter the dollar amount inserted into the slot machine: 100输入投入老虎机的美元金额:100

Orange Cherry Cherry橙樱桃樱桃

Congratulations, you won $ 100恭喜,你赢了 100 美元

this is what I've came up with so far and not sure if this is even close to correct:这是我到目前为止提出的,不确定这是否接近正确:

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int amount;
    int Apple;
    int Orange;
    int Peach;
    int Pineapple;
    
    System.out.println("Enter the dollar amount inserted into the slot "
            + "machine");
    amount = input.nextInt();
    System.out.println("The dollar amount is " + amount);
    
    Apple = 1;
    Orange = 2;
    Pineapple = 3;
    Peach = 4;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM