forked from quanke/design-pattern-java-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiddleState.java
More file actions
34 lines (32 loc) · 729 Bytes
/
Copy pathMiddleState.java
File metadata and controls
34 lines (32 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class MiddleState extends AbstractState
{
public MiddleState(AbstractState state)
{
this.acc=state.acc;
this.point=state.getPoint();
this.stateName="高手";
}
public void writeNote(int score)
{
System.out.println(acc.getName() + "发布留言" + ",增加" + score + "*2个积分。");
this.point+=score*2;
checkState(score);
System.out.println("剩余积分为:" + this.point + ",当前级别为:" + acc.getState().stateName + "。");
}
public void checkState(int score)
{
if(point>=1000)
{
acc.setState(new HighState(this));
}
else if(point<0)
{
System.out.println("余额不足,文件下载失败!");
this.point+=score;
}
else if(point<=100)
{
acc.setState(new PrimaryState(this));
}
}
}