package com.lovecoding.day14.ex01;

//多个线程通信 三个以上
public class PrintLetter {

    private static char letter = 'a';

    private static int flag = 0;

    //输出小写
    public synchronized void printLower(){
        //判断
        if (flag != 0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //输出
        for (int i = 1; i <=3 ; i++) {
            System.out.println( Thread.currentThread().getName()+"：" + (char)(++letter));
            if (letter> 'z'){
                letter = 'a';
            }
        }
        //改变状态
        flag=1;
        //通知
        notify();

    }

    //输出大写  -32
    public synchronized void printUpper(){
        //判断
        if (flag != 1){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //输出、
        for (int i = 1; i <= 3; i++) {
            System.out.println( Thread.currentThread().getName()+"：" + (char) (++letter-32));
            if (letter> 'z'){
                letter = 'a';
            }
        }

        //改变状态
        flag=0;
        //通知
        notify();

    }


}
