Question: 3) Create a public method that will return the total bases for a baseball player. To calculate total bases we start with 4 values -
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 valdes and multiply each by their respective base value, a single is worth 1 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 I 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+ (102 ) + ( 2 3) + (5. 4) = 71 total bases. Answer: public int totalBases( int singles, int doubles, int triples, int home runs) return (singlese 1) + (doubles+ 2) + (triples. 3) + (hone 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 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 the Number of Yards Gains, int numberOfCarries) return (double the berofYards Gains / number of Yards carries; 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 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 example10 singles, 4 doubles, triple. I hone 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 Forslun percentage of 450. Integer division ay need to be avoided again. Answer: public int sluggingPercentage (int Singles, int double, int triples, int honeRunsintatilats) 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 valdes and multiply each by their respective base value, a single is worth 1 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 I 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+ (102 ) + ( 2 3) + (5. 4) = 71 total bases. Answer: public int totalBases( int singles, int doubles, int triples, int home runs) return (singlese 1) + (doubles+ 2) + (triples. 3) + (hone 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 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 the Number of Yards Gains, int numberOfCarries) return (double the berofYards Gains / number of Yards carries; 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 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 example10 singles, 4 doubles, triple. I hone 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 Forslun percentage of 450. Integer division ay need to be avoided again. Answer: public int sluggingPercentage (int Singles, int double, int triples, int honeRunsintatilats)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
