随机选择航班城市

时间:2021-09-13 09:08:21

package nicetime.com.baseutil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

/**
* @author nicetime
* @create 2018-10-14 12:07
*/
public class RandFlightUtil {
public static void main(String[] args) {

//座位及经济舱信息
String[] seatPrefArr={"Aisle","Window","None"};
String[] seatTypeArr={"First","Business","Coach"};

//生成一个随机数0~3
int rand=new Random().nextInt(3);

//随机获取一个数组中的值
String seatPref=seatPrefArr[rand];
String seatType=seatTypeArr[rand];

// vars.put("seatPref",seatPref);
// vars.put("seatType",seatType);

System.out.println("seatPref="+seatPref+"-seatType="+seatType);

//航班城市信息
String[] city={"Denver", "Frankfurt", "London", "Los Angeles", "Paris", "Portland", "San Francisco", "Seattle", "Sydney", "Zurich"};

//生成一个随机位置的数字,用于随机取数字
int index1=new Random().nextInt(10);

int index2=new Random().nextInt(10);

//出发城市
String depart=city[index1];

while (index1==index2)
{
index2=new Random().nextInt(10);
}

//到达城市
String arrive=city[index2];

// vars.put("depart",depart);
// vars.put("arrive",arrive);

System.out.println("depart="+depart+"-arrive="+arrive);

}
}