1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
VladimirAG [237]
3 years ago
12

SummaryIn this lab, you complete a partially prewritten Java program that uses an array.The program prompts the user to interact

ively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help you write the remainder of the program.Instructions1.Ensure the file named BattingAverage.java is open.Write the Java statements as indicated by the comments.Execute the program by clicking "Run Code." Enter the following batting averages: .299, .157, .242, .203, .198, .333, .270, .190. The minimum batting average should be .157, and the maximum batting average should be .333. The average should be .2365.import java.util.Scanner;public class BattingAverage{public static void main(String args[]){Scanner s = new Scanner(System.in);// Declare a named constant for array size here.// Declare array here.// Use this integer variable as your loop index.int loopIndex;// Use this variable to store the batting average input by user.double battingAverage;// String version of batting average input by user.String averageString;// Use these variables to store the minimim and maximum batting averages.double min, max;// Use these variables to store the total and the average.double total, average;// Write a loop to get batting averages from user and assign to array.System.out.println("Enter a batting average: ");averageString = s.nextLine();battingAverage = Double.parseDouble(averageString);// Assign value to array.// Assign the first element in the array to be the minimum and the maximum.min = averages[0];max = averages[0];// Start out your total with the value of the first element in the array.total = averages[0];// Write a loop here to access array values starting with averages[1]// Within the loop test for minimum and maximum batting averages.// Also accumulate a total of all batting averages.// Calculate the average of the 8 averages.// Print the averages stored in the averages array.// Print the maximum batting average, minimum batting average, and average batting average.System.exit(0);}{
Computers and Technology
1 answer:
Andrej [43]3 years ago
8 0

Answer:

The complete program is as follows:

import java.util.Scanner;

public class Main{

   public static void main(String args[]){

       Scanner s = new Scanner(System.in);

       final int lent = 8;

       Double averages[] = new Double[lent];

       int loopIndex;

       double battingAverage;

       String averageString;

       double min, max;

       double total, average;

       for(loopIndex = 0;loopIndex<lent;loopIndex++){

       System.out.print("Enter a batting average: ");

       averageString = s.nextLine();

       battingAverage = Double.parseDouble(averageString);

       averages[loopIndex] = battingAverage;        }

       min = averages[0];max = averages[0];

       total = averages[0];

       for(loopIndex = 1;loopIndex<lent;loopIndex++){

       if(averages[loopIndex]>=max){

           max = averages[loopIndex];        }

       if(averages[loopIndex]<=min){

           min = averages[loopIndex];        }

       total+=averages[loopIndex];        }

       battingAverage = total/8;

       for(loopIndex = 0;loopIndex<lent;loopIndex++){

       System.out.println(averages[loopIndex]+" ");        }

       System.out.println("Average: "+battingAverage);

       System.out.println("Minimum: "+min);

       System.out.println("Maximum: "+max);

       System.exit(0);

       }}

Explanation:

See attachment for complete program with comments

Download txt
You might be interested in
Give three facts about the history of the train shongololo
monitta
<span>began operating in 1995
shongololo means </span><span> “to roll up”
non- profit organization </span>
3 0
3 years ago
Problem 8 - Recursive Divisible by 3 and 5 Complete the divBy3And5 function which accepts a list of integers. The function shoul
slavikrds [6]

The recursive function divBy3And5 is defined in Python and is found in the attached image.

In the base case, the function divBy3And5 tests if the input list is empty. If so, the tuple returned is (0, 0). This means no numbers are divisible by three and no numbers are divisible by five.

The recursive step gets the first element of the list and

  • If divisible by 3, it sets <em>count_of_3</em> to 1, else it leaves it as 0
  • If divisible by 5, it sets <em>count_of_5</em> to 1, else it leaves it as 0

It then makes a recursive call on the remaining elements, and stores it in a variable as follows

   <em>divBy3And5_for_remaining_elem</em> = divBy3And5(remaining_elements)

Then, it returns the tuple

       (<em>divBy3And5_for_remaining_elem</em>[0] + <em>count_of_3</em>,

                <em>divBy3And5_for_remaining_elem</em>[1] + <em>count_of_5)</em>

Learn more about recursion in Python: brainly.com/question/19295093

5 0
2 years ago
Mike wants to build an amplifier. which technology can he use?
STatiana [176]
A.
Not B because a guitar has no moving parts.
Not C because guitars receive all the power they need from a cord.
And not D because a guitar is not a car and doesn't need to move!
4 0
3 years ago
Write a simple algorithm in pseudocode that asks the user their favourite colour and then agrees with their choice, quoting the
olga55 [171]

Answer:

i am still a beginner in this but i hope it helps.

  • add scanner object;
  • declare string FavColour;
  • print msg to ask user for input
  • scan input FavColour;
  • print msg (" your favourite colour is " + FavColour)

3 0
3 years ago
What does it mean for a computing system to have an interface? A. An interface is a conduit through which the user can interact
Wittaler [7]

Answer:

An interface device (IDF) is a hardware component or system of components that allows a human being to interact with a computer, a telephone system, ...

Explanation:

5 0
1 year ago
Other questions:
  • If you choose a career, you will always be satisfied with your work.<br> True<br> False
    7·2 answers
  • Which of the following is NOT a logical operator (logical connective)?
    5·1 answer
  • Once you create a slide show, it is not easy to rearrange things, so you should plan your presentation ahead of time.
    14·1 answer
  • Why is it important to try to make financial decisions without emotions.
    12·2 answers
  • In cell h13, insert a pmt function to calculate the payments for students who want to pay for their trips in three installments.
    11·1 answer
  • What is the first step to apply the line and page breaks options to groups of paragraphs in a Word document?
    10·2 answers
  • A pre-design document you can use to create a new project quickly
    5·1 answer
  • False
    8·1 answer
  • By convention only, either the first usable address or the last usable address in a network is assigned to the router (gateway)
    11·1 answer
  • A major retailer wants to enhance their customer experience and reduce losses
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!