Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED HELP WITH THE SECOND PART IN BOLD. We are going to create a Java console application to see just how hot it was.

I NEED HELP WITH THE SECOND PART IN BOLD.

We are going to create a Java console application to see just how hot it was. In order to accomplish this challenge, I would like you to create an array of 31 elements to store each of the day's high temperatures in LA during the month of October. Note that the daily temperatures below are reported as whole numbers, just as they are among all forecasts, so please create an integer array.

Your application should prompt the user to enter all 31 days (high temperatures only), then report the highest temperature recorded during the month, the "average high" temperature and the most frequent high temperature (e.g. the mode).

Please see the following for a sample transaction with a user:

Please enter daily high for October 01: 78 Please enter daily high for October 02: 79 Please enter daily high for October 03: 78 Please enter daily high for October 04: 79 Please enter daily high for October 05: 85 Please enter daily high for October 06: 92 Please enter daily high for October 07: 95 Please enter daily high for October 08: 82 Please enter daily high for October 09: 87 Please enter daily high for October 10: 88 Please enter daily high for October 11: 76 Please enter daily high for October 12: 77 Please enter daily high for October 13: 87 Please enter daily high for October 14: 95 Please enter daily high for October 15: 96 Please enter daily high for October 16: 95 Please enter daily high for October 17: 94 Please enter daily high for October 18: 86 Please enter daily high for October 19: 78 Please enter daily high for October 20: 75 Please enter daily high for October 21: 95 Please enter daily high for October 22: 93 Please enter daily high for October 23: 102 Please enter daily high for October 24: 104 Please enter daily high for October 25: 100 Please enter daily high for October 26: 93 Please enter daily high for October 27: 86 Please enter daily high for October 28: 80 Please enter daily high for October 29: 73 Please enter daily high for October 30: 69 Please enter daily high for October 31: 69

~~~~~~~~~~Temperature Statistics~~~~~~~~~~ October's highest daily temperature was: 104 October's average high temperature was: 86.0 October's most frequent high temp was: 95

Extend IC18_LATemps to perform all data entry and calculations in one loop (it can be done!). Also, if there is more than one mode (meaning that more than one temperature is the most frequent), I'd like you to report the modes as follows: [if there are exactly 2 modes] October's most frequent high temps were Bimodal (two modes): 78 95 -or- [if there are > 2 modes, it is called a "multi-modal" scenario] October's most frequent high temps were Multi-modal (more than two modes): 78 90 95

THIS IS MY CODE SO FAR:

import java.text.DecimalFormat;

import java.util.Arrays;

import java.util.Scanner;

public class LATemps {

public static final int SIZE = 31;

public static void main(String[] args) {

// TODO Auto-generated method stub

int[] temps = new int[SIZE];

DecimalFormat twoDigits = new DecimalFormat("00");

DecimalFormat oneDPs = new DecimalFormat("0.0");

int max;

int maxFreq =0;

int mode=0;

double sum = 0.0;

Scanner consoleScanner = new Scanner(System.in);

double average = sum/SIZE;

for (int i = 0; i < temps.length; i++)

{

System.out.print("Please enter the daily high for October "+twoDigits.format(i+1)+": ");

temps[i] = consoleScanner.nextInt();

sum += temps[i];

}

consoleScanner.close();

average = sum/SIZE;

Arrays.sort(temps);

max = temps[temps.length-1];

//Decalre the freqs of the array to store all the temperature

int[] freqs = new int[max+1];

//Loop through the temps array and keep a count (frequency) of each temp:

// Use a for each loop to go through elements (temps) rather than positions

// for( : name of the collection)

for(int temp :temps)

{

//Look up the frequency of that temp and add 1 to it

freqs[temp]++;

}

//Loop through the freqs array

for (int i=0; i

{

//Determine the maxFreq

if (freqs[i]>maxFreq)

{maxFreq = freqs[i];

mode=i;

}

}

System.out.println("~~~~~~~~~~~~~~~Temperature Statistics~~~~~~~~~~~~~~~");

System.out.println("October's highest daily temperature was: "+max

+" October's average high temperature was: "+oneDPs.format(average)

+" October's most frequent high temp was: "+mode);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions