有一航空公司要一个新系统:
为这公司的唯一一架飞机安排座位(设飞机有十个座位),现在有两个选择如果是头等舱就输入number为1,再分座位它的作为只有5个就是1到5;
如果输入2就是经济舱它也只有5个座位是6到10;
现在小弟把基本的程序写出来的但是就是座位的随机分配不知道怎么写!
希望师傅们指教指教!谢谢的!
import java.io.*;public class kong{
/**
* init
*/
public void init(int number) {
int firstClass=0;
int economyClass=0;
if(number==1){
if(firstClass<5){
System.out.print("firstClass set is:");
}
else if(firstClass>=5&&economyClass<10){
System.out.print("Sorry firstclass is full,Economy class?");
}
else
System.out.print("Flight is full,Try next fligh");
}
if(number==2){
if(economyClass<10){
System.out.print("economyClass set is:");
}
else if(economyClass=10&&firstclass<5){
System.out.print("Sorrye conomyClass is full,first class?");
}
else
System.out.print("Flight is full,Try next fligh");
}
}
public static void mian(String arg[]){
int number = 0;
String s = " ";
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入数字:");
s = in.readLine();
number = Integer.parseInt(s);
}
catch (IOException e) {}
kong num = new kong();
num.init(number);
}}
为这公司的唯一一架飞机安排座位(设飞机有十个座位),现在有两个选择如果是头等舱就输入number为1,再分座位它的作为只有5个就是1到5;
如果输入2就是经济舱它也只有5个座位是6到10;
现在小弟把基本的程序写出来的但是就是座位的随机分配不知道怎么写!
希望师傅们指教指教!谢谢的!
import java.io.*;public class kong{
/**
* init
*/
public void init(int number) {
int firstClass=0;
int economyClass=0;
if(number==1){
if(firstClass<5){
System.out.print("firstClass set is:");
}
else if(firstClass>=5&&economyClass<10){
System.out.print("Sorry firstclass is full,Economy class?");
}
else
System.out.print("Flight is full,Try next fligh");
}
if(number==2){
if(economyClass<10){
System.out.print("economyClass set is:");
}
else if(economyClass=10&&firstclass<5){
System.out.print("Sorrye conomyClass is full,first class?");
}
else
System.out.print("Flight is full,Try next fligh");
}
}
public static void mian(String arg[]){
int number = 0;
String s = " ";
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入数字:");
s = in.readLine();
number = Integer.parseInt(s);
}
catch (IOException e) {}
kong num = new kong();
num.init(number);
}}
好象是Math.random()吧!
请你们指教咯
谢谢的!我是不知道用哦1
while(economyClass<6)
economyClass=(int)(10*Math.random()+1);
定义的时候这样应该行了啊,这样里面就不要判断了吧,1.0>Math.random()>=0.0的double型啊