java未定义类型_运算符>未定义为参数类型java.util.Random,java.util.Random

在if语句我尝试比较horse1的值和horse2和horse3的值。但我得到的错误: 他操作>未定义的参数类型java.util.Random中,java.util.Random的

import java.util.Scanner;

import java.util.Random;

public class RunHorseGame

{

public static void main(String[] args)

{

// TODO Auto-generated method stub

//variables

String name;

float bal;

float bet;

boolean nextRace;

int raceChoice;

int startRace;

Random horse1 = new Random(100);

Random horse2 = new Random(100);

Random horse3 = new Random(100);

Random horse4 = new Random(100);

Random horse5 = new Random(100);

Random horse6 = new Random(100);

Random horse7 = new Random(100);

Scanner input = new Scanner(System.in);

//welcome screen

System.out.println("Welcome to Horse Racing!");

System.out.println("Please enter your name:");

name = input.nextLine();

System.out.println("welcome " + name + ", you have a balance of $200!");

//create loop to repeat races when one finishes (keep balance)

nextRace = true;

while (nextRace == true)

{

bal = 200;

//give race options

System.out.println("Please select which race you would like to enter:");

System.out.println("Press 1 to enter: 3 horse race");

System.out.println("Press 2 to enter: 5 horse race");

System.out.println("Press 3 to enter: 7 horse race");

//create each race

//each horse has randomizer

//highest number wins race

raceChoice = input.nextInt();

switch(raceChoice)

{

case 1:

System.out.println("You have entered the 3 horse race!");

System.out.println("How much would you like to bet?");

bet = input.nextFloat();

System.out.println("You have bet " + bet + " dollars.");

bal =- bet;

System.out.println("Press 1 to start.");

System.out.println("Press 2 to go back to race selection.");

startRace = input.nextInt();

switch(startRace)

{

case 1:

if(horse1 > horse2 && horse1 > horse3)

{

}

break;

case 2:

nextRace = false;

break;

}

break;

case 2:

break;

case 3:

break;

default:

break;

}

nextRace = true;

}

}

}

+2

随机马1 =新随机(100); ** **不会使马1成为一个随机数达100(这是它看起来像你正在做的事情)。你只需要1个“随机”对象,那么马1,马2等将是整数或什么,你分配他们像'horse1 = myRandom.nextInt(100);' –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值