Skip to content

Commit 8ad9db0

Browse files
committed
Chapters 10 and 11
1 parent 5c1ab64 commit 8ad9db0

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

ch10/Player.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class Player
2+
{
3+
private String name;
4+
private int score;
5+
6+
public Player(String name)
7+
{
8+
this.name = name;
9+
this.score = 0;
10+
}
11+
12+
public void incrementScore()
13+
{
14+
this.score++;
15+
}
16+
17+
public void resetScore()
18+
{
19+
this.score = 0;
20+
}
21+
22+
public int getScore()
23+
{
24+
return score;
25+
}
26+
27+
public String getName()
28+
{
29+
return name;
30+
}
31+
}

ch10/PlayerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class PlayerTest
2+
{
3+
public static void main(String[] args)
4+
{
5+
Player playerName = new Player("Silent T");
6+
7+
8+
System.out.println("Player Name: " + playerName.getName());
9+
System.out.println("Starting score: " + playerName.getScore());
10+
11+
playerName.incrementScore();
12+
System.out.println(playerName.getScore());
13+
14+
playerName.incrementScore();
15+
System.out.println(playerName.getScore());
16+
17+
playerName.resetScore();
18+
System.out.println(playerName.getScore());
19+
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)