📄 saleslady.java
字号:
public class SalesLady {
int memontoes, five, ten;
public synchronized String ruleForSale(int num, int money) {
String s = null;
if (memontoes <= 0)
return "对不起,已经售完";
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -