Inlab 4: A Baseball League
Due: Wednesday 13 July at 6:00 pm
- Get more experience with programs involves interacting
- Address type-casting issues.
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
You will build a program that represents baseball teams. To do
this, you need two classes.
The Player class will represent a baseball player and the Team
class will represent a baseball team.
A Player will consist of a name, the number of at bats they had
(you are required to make this an integer),
and the number of hits they had (again, must be an int). A Team
will consist of three (exactly three) Players
and a team name. You will then build methods that will calculate
the batting average of the individual players
and the overall team. NOTE: Batting Average = numHit / numAtBats.
- Create a project called Inlab4.
- Type this code into a class called
Driver (Don't modify it unless you are doing the bonus point part). As discussed in class last week, you can gain a ton
of information about the classes and methods you need to build
from this code.
- Correctly implement the methods you need to get the Driver to
compile and run. HINT: It may be easiest to have the
printStats() method in the Team class (repeatedly) call a
printStats() method in the Player class.
- If implemented correctly, your output will look like this.
- Create static variables in both the Team and Player class that
will keep track of the number of instances of those classes
- Create three more Players and one more Team in the Driver.
- Modify the Driver so that it prints out the number of teams
and players in the league before the team statistics. Your
output should look like this.
By Wednesday afternoon at 6:00 pm, submit the files Player.java,
Team.java, and Driver.java (if you worked on the bonus point part) into the appropriate D2L dropbox folder. DO
NOT SUBMIT .class files.
Grading - 10 points
- 4 points - The new classes compile
with the provided Driver.
- 2 points - The batting average for a player is correctly
calculated, in the Player class, using type-casting.
- 2 points - The batting average for a team is correctly
calculated, in the Team class, using type-casting.
- 1 points - The output looks like the output provided.
- 1 points - Good programming principles are followed (minimal
unnecessary code, efficient solution,...).
- 1 bonus point - The second output is
replicated accurately using static variables and methods in the
Team and Player classes.