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
a. Fill in the blanks with suitable words: A software that controls and manages all the activities of the computer ... b. A soft
zavuch27 [327]

Explanation:

i don't know

4 0
2 years ago
GUYSSS!!!
otez555 [7]
Yea, I don’t think you can fix it unless you backed it up or something somehow...
8 0
3 years ago
Read 2 more answers
What is the name of the image window area that identifies the project you are working on?
Natali5045456 [20]
The answer is the title bar becuase it would tell the name of the project or something else such as when you are using Words then it would tell you the name of the title of the document you are doing.
6 0
3 years ago
Read 2 more answers
What is the easiest computer programming language​
RideAnS [48]

Answer:

Ther are 8 easiest computer programming language :

• HTML

• CSS

• Javascript

• Python

• Ruby

• Java

• PHP

• C/C++

5 0
2 years ago
Write switch-case statement that displays the following information if the temperature is the input Activities at Lake LazyDays
Marta_Voda [28]

Answer:

//here is code in c++.

#include <bits/stdc++.h>

using namespace std;

int main()

{

// variable

int temp;

cout<<"Please enter the temperature:";

//read temperature from user

cin>>temp;

int n;

// reduce the case for switch

n=temp/10;

// print output according to the switch case

switch (n) {

case 7:

case 6:

cout<<"tennis"<<endl;

break;

case 5:

case 4:

cout<<"golf"<<endl;

break;

default:

if(temp>=80)

cout<<"swimming"<<endl;

else

cout<<"skiing"<<endl;

break;

}

return 0;

}

Explanation:

Read the value of temperature from user and assign it to variable "temp".

Calculate n=temp/10, to limit the number of cases in the switch statement.

if temperature is greater or equal 60 & less than 80, it will print "tennis".

If temperature is greater or equal 40 & less than 60, it will print "golf".

in default case, if temperature is greater than 80, it will print "swimming".

if less than 40, print "skiing".  

Output:

Please enter  the temperature::67                                                                                        

tennis

3 0
3 years ago
Other questions:
  • It is a good idea to use more than one typeface in a document when _____.
    8·2 answers
  • What's the best option if you can't show your PowerPoint presentation at all? A. Create PDF/XPS Document B. Prepare a Package Pr
    11·2 answers
  • tuition $36,620 room and board $12,900 books and fees $2,450 transportation $3,100 other $1,330 . Emily is using the table to de
    8·2 answers
  • When you use a script to create all of the tables for a database, you must start with the tables that don't have _______________
    15·1 answer
  • An application with which you can perform calculations on numbers and work with other data
    8·1 answer
  • Write a program that extracts the last three items in the list sports and assigns it to the variable last. Make sure to write yo
    8·1 answer
  • Technician A says that a lead acid battery uses straight Hydrochloric acid for electrolyte. Technician B says that a lead acid b
    10·2 answers
  • To insert text from a separate file into your Word document
    10·1 answer
  • At a red traffic light, you must stop__
    12·2 answers
  • The ________ is the biggest power consumer on a mobile computing device.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!