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
user100 [1]
3 years ago
10

Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar ye

ar. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods:
Computers and Technology
1 answer:
abruzzese [7]3 years ago
7 0

Answer:

Java program is explained below with appropriate comments

Explanation:

Temperature.java

import java.util.Scanner;

public class Temperatures {

public static Scanner keyboard = new Scanner(System.in);

private static int highTemperature, lowTemperature,averageHigh, averageLow;

private static int index;//keeps track of months

private static int indexOfHighestTemp=0, indexOfLowestTemp=0;

private static int[][] highAndLowTemps = new int [12][2];//array for highs and lows

private static String[] months = new String[12];//array of monthss

public static void main(String[] args) {

inputTempForYear();

calculateAverageHigh(highAndLowTemps);

calculateAverageLow(highAndLowTemps);

findHighestTemp(highAndLowTemps);

findLowestTemp(highAndLowTemps);

//outputs results

System.out.println("Average High: "+averageHigh);

System.out.println("Average Low: "+averageLow);

System.out.println("Highest Temp and Month: "+highAndLowTemps[indexOfHighestTemp][0]+" "+months[indexOfHighestTemp]);

System.out.println("Lowest Temp and Month: "+highAndLowTemps[indexOfLowestTemp][1]+" "+months[indexOfLowestTemp]);

}

private static void inputTempForMonth(int[][] highAndLowTemps)

{

System.out.println("Input the high temperature for "+months[index]+":");

highTemperature = keyboard.nextInt();//inputs months high temp

highAndLowTemps[index][0]=highTemperature;

System.out.println("Input the low temperature for "+months[index]+":");

lowTemperature = keyboard.nextInt();//inputs months low temp

highAndLowTemps[index][1]=lowTemperature;

}

private static int[][] inputTempForYear()

{

months[0]="January";

months[1]="Febuary";

months[2]="March";

months[3]="April";

months[4]="May";

months[5]="June";

months[6]="July";

months[7]="August";

months[8]="September";

months[9]="October";

months[10]="November";

months[11]="December";//fills month array

for (index=0;index<=11;index++)//fills array with highs and lows

{

inputTempForMonth(highAndLowTemps);

}

return highAndLowTemps;

}

private static int calculateAverageHigh(int[][] highAndLowTemps)

{

for(int i=0;i<=11;i++)//finds sum of high temps

{

averageHigh=averageHigh+highAndLowTemps[i][0];

}

averageHigh/=12;//calculates average

return averageHigh;

}

private static int calculateAverageLow(int[][] highAndLowTemps)

{

for(int i=0;i<=11;i++)//finds sum of low temps

{

averageLow=averageLow+highAndLowTemps[i][1];

}

averageLow/=12;//calculates average

return averageLow;

}

private static int findHighestTemp(int[][] highAndLowTemps)

{

double max=highAndLowTemps[0][0];

int indexHigh;//index for highest

for(indexHigh=0;indexHigh<11;indexHigh++)//find highest high temp

{

if(highAndLowTemps[indexHigh][0]>max)

{

max=highAndLowTemps[indexHigh][0];

indexOfHighestTemp=indexHigh;

}

}

return indexOfHighestTemp;

}

private static int findLowestTemp(int[][] highAndLowTemps)

{

double min=highAndLowTemps[0][1];

int indexLow;//index for lowest

for(indexLow=0;indexLow<11;indexLow++)//finds lowest low temp

{

if(highAndLowTemps[indexLow][1]<min)

{

min=highAndLowTemps[indexLow][1];

indexOfLowestTemp=indexLow;

}

}

return indexOfLowestTemp;

}

}

You might be interested in
What data does Bittorrenting uses? Explain.
amid [387]

Answer:

A BitTorrent software consumer utilizes that data into the torrent data to communicate special tracker and support shifting of that data among networks including either complete or incomplete representations about the data-set.

Explanation:

BitTorrent is based at the thought of any torrent, which is a smallish data that includes metadata regarding a host, specific tracker, that organizes the data sharing and data that is distributed. A peer that wants to advance data available need first attain a tracker for the data, generate a torrent and later share the torrent data. Different peers can next use the information included in the torrent file support all other in downloading that data. That download is organized by that tracker.

5 0
3 years ago
What is a computer? ​
miv72 [106K]
<h2><em>what is a computer? </em></h2>

  • <em>A <u>computer</u> is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. </em>

<em>hope </em><em>it</em><em> helps</em>

<em>#</em><em>c</em><em>a</em><em>r</em><em>r</em><em>y</em><em> </em><em>on</em><em> learning</em>

5 0
3 years ago
Read 2 more answers
Impaired drivers not only harm themselves but they harm other individuals and affect our _________________.
lawyer [7]

entire society. impaired drivers affect all of those things.

4 0
4 years ago
Read 2 more answers
IBM’s system that is built on the middle ground approach to AI.
Norma-Jean [14]

Answer:

IBM Watson is AI for business. Watson helps organizations predict future outcomes, automate complex processes, and optimize employees' time.

Explanation:

6 0
3 years ago
discuss the advantages and disadvantages that Excel has in helping navigate databases, big data, and data analytics.
posledela

Answer:

 The main advantage of using the the excel that help in navigating the databases and helps in data analytics. It basically exploring huge information and databases are predominantly the information purging methods in exceed expectations which aides in preparing information in an expedient and proficient way.

The information purging procedure incorporate VBA macros or rotate tables, mapping instruments, report causing utilizing progressed to exceed expectations devices and furthermore has the upside of reconciliation with different virtual products.

The disadvantage are as follows:

  • It is difficult for sharing the spreadsheet in the system.
  • It also face difficulty while observing the any type of the regular tends in the given data.

5 0
3 years ago
Other questions:
  • The ____ operator eliminates duplicate values in the results of a query.
    11·1 answer
  • What are the 6 external parts of a computer system
    8·1 answer
  • Please help!
    10·2 answers
  • Write a command that will start and run the gedit command in the background.
    8·1 answer
  • Which of the following might not exist in a URL?
    10·2 answers
  • A sonar operator on a battleship looks at a display that contains a spatial layout of the distribution of echoes from the surrou
    6·1 answer
  • What is working with others to find a mutually agreeable outcome?
    8·2 answers
  • Electrical data suitable for transmission is called a(n)
    5·1 answer
  • Wap to calculate the simple interest for the given PTR​
    14·1 answer
  • onsider a file system on a disk that has both logical and physical block sizes of 512 bytes. assume that the information about e
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!