设每10秒钟来一辆出租车接走4名乘客(1秒时第一辆出租车出站),
1 11 21 31 41 51
每60秒来一辆中客可接走16名乘客(60秒时第一辆中客出站)
60 120 180 240
每4秒钟会进入站内1名新乘客,(0秒时来第一个新乘客)
1.问何时站内乘客数第一次为0 ?
2.站内乘客数第一次为0时,
共接走多少乘客?共用多少辆出租车?共用多少辆中型客车?
* */
/**
* @描述:多线程作业(车站)
* @作者:郭立
* @版本:1.0
* @开发时间:2013-11-10上午9:30:57
*/
package cn.com.shxt.test;
public class HomeWork {
static int sopp = 78 ;
static int texi = 0 ;
static int bus = 0 ;
static int time = 0 ;
public static void main(String[] args) {
HomeWork h = new HomeWork();
h.start();
boolean log = true;
while(log){
if(sopp<0){
System.out.println("第一次车站人数为0");
System.out.println("共用出租车"+texi);
System.out.println("共用客车"+bus);
log=false;
}
}
}
public void start(){
texi t = new texi();
t.start();
people p = new people();
p.start();
bus b = new bus();
b.start();
timer tm = new timer();
tm.start();
}
class texi extends Thread{
@Override
public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("一秒过后");
while(sopp>0){
sopp = sopp - 4;
texi++;
System.out.println("被第"+texi+"辆出租车接走后车站还有"+sopp+"乘客");
try {
sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class people extends Thread{
@Override
public void run() {
while(sopp>0){
sopp++;
System.out.println("车站新来乘客后共有人数"+sopp+"位");
try {
sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class bus extends Thread{
@Override
public void run() {
while (sopp>0) {
try {
sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}
bus++;
sopp = sopp - 16;
System.out.println("来了第"+bus+"两中型客车接走16人后车站还有"+sopp+"人");
}
}
}
class timer extends Thread{
@Override
public void run() {
while(sopp>0){
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
time++;
System.out.println(time+"秒过去了:\n");
}
}
}
}