forked from quanke/design-pattern-java-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighState.java
More file actions
41 lines (38 loc) · 1008 Bytes
/
Copy pathHighState.java
File metadata and controls
41 lines (38 loc) · 1008 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
35
36
37
38
39
40
41
public class HighState extends AbstractState
{
public HighState(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 downloadFile(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<0)
{
System.out.println("余额不足,文件下载失败!");
this.point+=score;
}
else if(point<=100)
{
acc.setState(new PrimaryState(this));
}
else if(point<=1000)
{
acc.setState(new MiddleState(this));
}
}
}