Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a public method that will return the slugging percentage (decimal) for a baseball player. Slugging percentage is calculated as total bases divided by at

image text in transcribed
image text in transcribed
Create a public method that will return the slugging percentage (decimal) for a baseball player. Slugging percentage is calculated as total bases divided by at bats. We created a method in number 3 that can determine the total bases when it knows the number of singles, doubles, triples, and home runs. This slugging percentage method should accept those four values again, like the total bases method, plus one additional int parameter for the number of at bats. In the end, there will be 5 int parameters defined in the signature. For the body we will divide the total bases by the at bats, but instead of listing the total bases math logic again, we should call the method defined in question 3. This method call requires 4 arguments to be passed and you will use the parameters defined in this new slugging percentage method and pass them through to the total bases method. For example, 10 singles, 4 doubles, 1 triple, 1 home run, 55 at bats - call total bases method passing in singles, doubles, triples, home runs and it will return 25 total bases, then divide 25 by 55 for a slugging percentage of .454. Integer division may need to be avoided again. 3) Create a public method that will return the total bases for a baseball player. To calculate total bases we start with 4 values - the number of singles, doubles, triples, and home runs an individual player has. We will define 4 parameters, all integer values, to represent each. In the body we will take the 4 values and multiply each by their respective base value, a single is worth i base, a double worth 2 bases, a triple worth 3 bases, a home run worth 4 bases. After multiplying each parameter by its base value, we add all four values together for the total number of bases. For example, if a player has 10 singles, 4 doubles, 1 triple, and 1 home run - we would use this calculation: (10 * 1) + (4 + 2) + (1 * 3) + (1 * 4) = 25 total bases. If a player has 25 singles, 10 doubles, 2 triples, 5 home runs = 25+ (10 + 2) + (2 + 3) + (5 + 4) = 71 total bases. Answer: public int totalBases( int singles, int doubles, int triples, int hone runs) return (singles* 1) + (doubles+ 2) + (triples* 3) + (home runs. 4); Create a public method that will return the yards per carry (decimal) for a running back. To calculate yards per carry we start with 2 values - the number of yards gained, and the number of carries. Both yards and carries are int values only. To calculate the return value, divide the number of yards by the number of carries. The division (and method) should allow for the return of decimal values so integer division may need to be avoided. For example, if a player has 207 yards in 45 carries, the method would divide the two values and return 4.6 - each carry earned an average of 4.6 yards. If a player has 1254 yards in 287 carries, the method would return 4.369. Answer: public double calculateYardsPerCarry (int theNumberOfYards Gains, int numberOfCarries) return (double) theNumberOfYardsGains / number of YardsCarries; 5) Create a public method that will return the slugging percentage (decimal) for a baseball player. Slugging percentage is calculated as total bases divided by at bats. We created a method in number 3 that can determine the total bases when it knows the number of singles, doubles, triples, and home runs. This slugging percentage method should accept those four values again, like the total bases method. plus one additional int parameter for the number of at bats. In the end, there will be 5 int parameters defined in the signature. For the body we will divide the total bases by the at bats, but instead of listing the total bases math logic again, we should call the method defined in question 3. This method call requires 4 arguments to be passed and you will use the parameters defined in this new slugging percentage method and pass the through to the total bases method. For example, 10 singles, 4 doubles, 1 triple, 1 home run, 55 at bats - call total bases method passing in Singles, doubles, triples, home runs and it will return 25 total bases, then divide 25 by 55 for a stugging percentage of .454. Integer division may need to be avoided again

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

6. Vanguard

Answered: 1 week ago