Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Needs help with Java programming language. Project 4: Baseball Simulator The objective of this assignment is to gain experience writing classes that conform to a

Needs help with Java programming language.

Project 4: Baseball Simulator

The objective of this assignment is to gain experience writing classes that conform to a set of requirements and using those methods in a program.

Your task is to write a program to simulate a batter facing a pitcher in a baseball game. Your program should include a Batter class with the following fields and methods:

private String name

private double average

/* Assumes the pitcher has thrown a strike, uses this batters average to determine whether he hits the pitch (method returns true) or swings and misses (method returns false). */ public boolean hit()

public String getName() // returns the Batters name You will also need to write a Pitcher class with the following fields and methods:

private String name

private double average

/* Uses this pitchers average to determine whether he throws a strike (method returns true) or a ball (method returns false). */ public boolean pitch()

public String getName() // returns the Pitchers name

You will then need to write a driver program that instantiates a Pitcher object and a Batter object and simulates an at-bat. The rules for this simulation are as follows:

If a Pitchers average is, for example, .80 then 80 percent of the time calling the Pitcher classs pitch method should return true and 20 percent of the time it should return false.

The Batter never swings at a ball and he always swings at a pitch in the strike zone. If the pitch is in the strike zone, the Batters hit method should be called. If the Batters average is .25 then 25 percent of the time, that method should return true (indicating a hit) and 75 percent of the time it should return false (indicating a swing and a miss).

If the Batters name is John Doe and he gets a hit, your driver program should display the message John Doe got a hit!

Your driver program should keep track of the number of balls and strikes. If the number of balls reaches four, the program should display the message John Doe walked. If the number of strikes reaches three, it should display the message John Doe struck out.

After each pitch, your program should display the number of balls and strikes. Three example runs of the program are shown below:

Phil Hughes is pitching to Alex Rodriguez

Alex Rodriguez swung and missed

The count is 0 balls and 1 strikes

Alex Rodriguez got a hit!

Phil Hughes is pitching to Chase Headley

Chase Headley swung and missed The count is 0 balls and 1strikes

Chase Headley swung and missed

The count is 0 balls and 2 strikes

Phil Hughes threw a ball The count is 1balls and 2 strikes

Chase Headley swung and missed

The count is 1 balls and 3 strikes

Chase Headley struck out.

Phil Hughes is pitching to Carlos Beltran

Carlos Beltran swung and missed

The count is 0 balls and 1 strikes

Phil Hughes threw a ball

The count is 1 balls and 1 strikes

Phil Hughes threw a ball

The count is 2 balls and 1 strikes

Carlos Beltran swung and missed

The count is 2 balls and 2 strikes

Phil Hughes threw a ball

The count is 3 balls and 2 strikes

Phil Hughes threw a ball

The count is 4 balls and 2 strikes

Carlos Beltran walked.

-----------------------------------------------------------------------------------------

Rubric (all items are worth one point):

1-The Pitcher and Batter classes contain the requested fields and methods.

2-The hit and pitch methods produce the requested percentage of hits and strikes

3-The driver program instantiates Pitcher and Batter objects and calls methods on those objects

4-The driver program produces the appropriate output in response to hits, walks and strike outs.

5-The program recognizes when the at-bat is over

6-The program follows the style guidelines and good programming principles. In particular, all fields are private.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago