package org.cctv1;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test8 {
 
 public static void main(String[] args) {
  Scanner s = new Scanner(System .in);
  Air air = new Air(5);
  while(air.number>1){
   System.out.println("请订票:");
   String str = s.nextLine();
   D1 d = new D1(str,air,-1);
   d.start();
  }
 }

}
class Air{
 int number;
 
 public Air(int number){
//  this.name = name;
  this.number = number;
//  this.place = place;
 }
 public synchronized void f(int a ) throws InterruptedException{
  Thread.sleep(1000);
  number+=a;
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日   hh:mm:ss");
  String str = sdf.format(new Date());
  System.out.println(Thread.currentThread().getName()+"订了一张飞往美国的机票"+"剩余"+number+"张票        "+str);
  System.out.println(".....................................");
 }
}
class D1 extends Thread{
 Air air = null;
 int b;
 public D1(String name, Air air, int b){
  super(name);
  this.air =air;
  this.b = b;
 }
 @Override
 public void run() {
  try {
   air.f(b);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }
}