H:\CSC120\Java\lec11\src\BaseballHitter.java |
1
2
3
4
5
6
7
8
9 @author
10
11 public class BaseballHitter {
12
13 private String name;
14 private Integer atBats, hits, rbis;
15 private Boolean isSwitchHitter;
16
17
18 public BaseballHitter( String n, Integer ab, Integer h, Integer r, Boolean sh ) {
19 name = n;
20 atBats = ab;
21 hits = h;
22 rbis = r;
23 isSwitchHitter = sh;
24 }
25
26
27
28
29 public String getName() {
30 return name;
31 }
32
33 public Integer getAtBats() {
34 return atBats;
35 }
36
37 public Integer getHits() {
38 return hits;
39 }
40
41 public Integer getRBIs() {
42 return rbis;
43 }
44
45 public Boolean getIsSwitchHitter() {
46 return isSwitchHitter;
47 }
48
49
50
51
52 public void setName( String n ) {
53 name = n;
54 }
55
56 public void setAtBats( Integer ab ) {
57 atBats = ab;
58 }
59
60 public void setHits( Integer h ) {
61 hits = h;
62 }
63
64 public void setRBIs( Integer r ) {
65 rbis = r;
66 }
67
68 public void setIsSwitchHitter( Boolean sh ) {
69 isSwitchHitter =
70 sh;
71 }
72
73
74
75
76 public String toString() {
77 return name + " has " + hits + " hits in "
78 + atBats + " atBats, and has driven in " + rbis
79 + " runs. It is "
80 + isSwitchHitter + " that " + name + " is a switch-hitter";
81 }
82
83
84 public Double calculateBattingAvg() {
85 return 1.0 * hits / atBats;
86 }
87
88
89 }
90
91
92
93
94
95
96
97
98