java座位预定程序代码,java座位预定程序代码是多少
用java写个简单的电影院座位预约,10个座位2行。前面的座位10000文,后面的20000文,
import java.util.Scanner;
成都创新互联公司专注于企业成都营销网站建设、网站重做改版、托克逊网站定制设计、自适应品牌网站建设、H5高端网站建设、商城网站定制开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为托克逊等各大城市提供网站开发制作服务。
/**
*
* @author 12052010
* @Date December 05,2014
*
*/
public class Film {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int [][] num = new int[2][10];
int fg1,fg2;//标志顾客选择 的座位fg1:排数 fg2:列数
for(int i=0;inum.length;i++){
for(int j=0;jnum[i].length;j++)
num[i][j]=0;//赋初值,所有座位没有被预定
}
randomBook(num);
System.out.print("\n-----------电影院座位订票情况(0:还没被预定 1: 已经被预定)------------");
for(int i=0;inum.length;i++){
System.out.println("");
for(int j=0;jnum[i].length;j++)
System.out.print(" "+num[i][j]);
}
/**
* 顾客输进的排数必须符合0 or 1
*/
do{
System.out.print("\nInput fg1: ");
fg1=input.nextInt();
} while(fg10||fg12);
/**
* 顾客输进的列数必须符合 0-9
*/
do{
System.out.print("Input fg2: ");
fg2=input.nextInt();
} while(fg20||fg29);
if(num[fg1][fg2]==1){
System.out.print("\n已经被人订了,不好意思");
}else{
System.out.print("\n你要订的座位是: "+ fg1+"排 "+ fg2+"列, 票价:");
if(fg1==1)
System.out.print("10000文");
else
System.out.print("20000文");
}
}
/**
* 随即设置电影院的座位被预定
*/
public static void randomBook(int[][] num){
for(int i=0;inum.length;i++){
for(int j=0;jnum[i].length;j++){
//随机设置
num[i][j]=(int)(Math.random()*2);
}
}
}
}
用java怎么实现随机分配座位,求代码?
public static void main(String[] args) {
LinkedListInteger ll=new LinkedListInteger();
for(int i=1;i51;i++){
ll.add(i);
}
int i=0;
while(ll.size()0){
i=(int)(ll.size()*Math.random());
System.out.println(ll.get(i));
ll.remove(i);
}
}
java随机分配!比如有五个座位a, b, c ,d ,e,有五个学生1,2,3,4,5 把学生分配到座位上不能有重复!求代码
import java.util.*;
public class a {
public static void main(String[] args) {
int i;
char c;
String[] a = {"座位1","座位2","座位3","座位4","座位5"};
/*生成座位list*/
ListString seat = new ArrayListString();
/*向其中添加座位*/
for(i = 0;i 5;i++){
seat.add(a[i]);
}
/*调用函数,将顺序打乱*/
Collections.shuffle(seat);
/*显示结果*/
for(i = 0,c = 'a'; c = 'e';c++,i++){
System.out.println("学生"+c+"坐在"+seat.get(i));
}
}
}
有问题追问我
java座位预定问题,有没有大神
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class Kyo
{
private static final String TXT = "booking.txt";
private static final String LINE = System.getProperty("line.separator");
private static String readLine(int line, int count, String file)
{
try
{
Scanner scan = new Scanner(new File(file));
scan.skip("([^" + LINE + "]+[" + LINE + "]+)" + "{" + (line + 1) + "}");
String result = "";
while(count 0 scan.hasNextLine())
{
result += scan.nextLine().trim();
if(count 1)
{
result += LINE;
}
count--;
}
scan.close();
return result;
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
return "";
}
private static void setBestSeat(String[] seat, String tag, String members, int num)
{
int[] seats = new int[0];
int[] indexs = new int[0];
for(int i = 0; i seat.length; i++)
{
String s = seat[i];
boolean isExisted = s.contains(tag);
if(s.contains(tag))
{
for(int j = i + 1; j i + num; j++)
{
if(j seat.length - 1)
{
isExisted = false;
break;
}
String b = seat[j];
if(!b.contains(tag))
{
isExisted = false;
break;
}
}
int[] dest = new int[seats.length + 1];
System.arraycopy(seats, 0, dest, 0, seats.length);
dest[dest.length - 1] = i;
seats = dest;
}
// 是否有足够的连续数组元素(座位数)
if(isExisted)
{
int[] dest = new int[indexs.length + 1];
System.arraycopy(indexs, 0, dest, 0, indexs.length);
dest[dest.length - 1] = i;
indexs = dest;
}
}
String[] ms = members.split("[" + LINE + "]+");
if(indexs.length == 0)
{
indexs = seats;
String tmp = ",";
for(int i = 0; i ms.length; i++)
{
int rand = (int) (Math.random() * indexs.length);
int ir = indexs[rand];
if(tmp.indexOf("," + ir + ",") == -1)
{
seat[ir] = "Seat " + (ir + 1) + ": " + ms[i];
tmp += ir + ",";
}
else
{
i--;
}
}
}
else
{
int rand = (int) (Math.random() * indexs.length);
int ir = indexs[rand];
for(int k = ir; k ir + ms.length; k++)
{
seat[k] = "Seat " + (k + 1) + ": " + ms[k - ir];
}
}
}
public static void main(String[] args)
{
String[] seat = {
"Seat 1: -empty-",
"Seat 2: -empty-",
"Seat 3: -empty-",
"Seat 4: -empty-",
"Seat 5: -empty-",
"Seat 6: -empty-",
"Seat 7: -empty-",
"Seat 8: -empty-"
};
String[][] booking = new String[0][];
Scanner input = null;
int count = 0;
int number = 0;
try
{
input = new Scanner(new File(TXT));
while(input.hasNextLine())
{
String line = input.nextLine().trim();
if(line.matches("^\\d+$"))
{
int num = Integer.parseInt(line);
if(num != seat.length)
{
String result = readLine(count, num, TXT);
setBestSeat(seat, "-empty-", result, num);
}
num = num == seat.length ? 2 : num + 1;
String[][] dest = new String[booking.length + 1][];
System.arraycopy(booking, 0, dest, 0, booking.length);
dest[dest.length - 1] = new String[num];
booking = dest;
booking[number][0] = line;
number++;
}
count++;
}
booking[0][1] = Arrays.toString(seat).replaceAll("[\\[\\]]", "");
input.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
for(int i = 0; i seat.length; i++)
{
System.out.println(seat[i]);
}
System.out.println(Arrays.deepToString(booking));
}
}
用Java做随机排座位程序
随机排座位,首先的知道有多少个座位吧?以下是60个座位的随机排序!
import java.util.Random;
public class select{ //建一个类命名为selcet.java
public static void main(String[] args)
{
System.out.println("随机的九个数是:");
int a[] = new int[60]; //总的有60个座位!
Random random = new Random();
for (int i=0;ia.length;i++)
{
int z = random.nextInt(60); //随机抽取60个座位
a[i] = Math.round(z);
if (i = 1)
{
int j = i;
while (j = 0)
{
if (a[i] == a[j])
{
int k = random.nextInt(60);//随机抽取60个座位
a[i] = Math.round(k);
}
j--;
}
}
System.out.print(a[i] + 1 + " ");
}
}
}
当前名称:java座位预定程序代码,java座位预定程序代码是多少
文章源于:http://azwzsj.com/article/dsgsejh.html