forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
52 lines (43 loc) · 1.17 KB
/
Copy pathTile.java
File metadata and controls
52 lines (43 loc) · 1.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
/**
* class for Scrabble tile
*/
public class Tile {
private char letter;
private int value;
//value constructor
public Tile(char letter, int value) {
this.letter = letter;
this.value = value;
}
//print method
public static void printTile(Tile tile) {
System.out.printf("%c: %d\n", tile.letter, tile.value);
}
//instantiating new instance of Tile
public static void testTile() {
Tile tile = new Tile('Z', 10);
printTile(tile);
}
//overloading toString method
public String toString() {
return String.format("%c: %d\n", this.letter, this.value);
}
//overloading equals method
public boolean equals(Tile that) {
return this.letter == that.letter && this.value == that.value;
}
//getters
public char getLetter() {
return this.letter;
}
public int getValue() {
return this.value;
}
//setters
public void setLetter(char letter) {
this.letter = letter;
}
public void setValue(int value) {
this.value = value;
}
}