Write a program to find a baseball player\'s batting average. The program should
ID: 3694215 • Letter: W
Question
Write a program to find a baseball player's batting average. The program should ask the user to enter the number of times the player was at bat and the number of hits he got It should then display his batting average to 4 decimal places. Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision. A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 "servings" in the bag and that a serving equals 300 calories. Write a program that asks the user to input how many cookies they actually ate and then reports how many total calories were consumed. A retail company must file a monthly sales tax report listing the sales for the monthExplanation / Answer
2.4
import java.util.*;
public class Average
{
public static void main(String[] args)
{
float avg, sum=0;
Scanner s = new Scanner(System.in);
float a[] = new float[5];
System.out.println("Enter all the elements:");
for(int i = 0; i < 5 ; i++)
{
a[i] = s.nextInt();
sum = sum + a[i];
}
System.out.println("Sum:"+sum);
avg = sum / 5;
System.out.println("Average:"+avg);
}
}
2.5
// Given there are 10 servings and bag contains 40 cookies, each serving contains 4 cookies i.e 40/4. //Therefore 4 cookies contains 300 calories. Each cookie contains 75 calories.
import java.util.*;
public class Calories
{
public static void main(String[] args)
{
int TotCal, c;
Scanner s = new Scanner(System.in);
System.out.println( " Enter no. of cookies ate : ");
c = s.nextInt();
TotCal = c*75;
System.out.println( " Total calories are : "+ TotCal);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.