?? saleslady.java
字號:
public class SalesLady {
int memontoes, five, ten;
public synchronized String ruleForSale(int num, int money) {
String s = null;
if (memontoes <= 0)
return "對不起,已經(jīng)售完";
if (money == 5) {
memontoes--;
five++;
s = "給你票," + "你的錢正好。";
} else if (money == 10) {
while (five < 1) {
try {
System.out.println("" + num + "號顧客用10元購票,請等待");
wait();
} catch (InterruptedException e) {
}
}
memontoes--;
five -= 1;
ten++;
s = "給你票," + "找你5元。";
}
//notifyAll();
return s;
}
SalesLady(int m, int f, int t) {
memontoes = m;
five = f;
ten = t;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -