Question
Please help my finish problem 1. Please edit my coding (shown below) about the highestTemps and lowestTemps.
Problem 1 Write a program called Temperatures that will read in a user specified number of temperatures into a double array. Then print the highest, lowest and average temperature. Write five separate methods in addition to the main method- one each for readTemps, highestTemp, lowestTemp, averageTemp and printTemps. The printTemps method should be a void method (it returns nothing) and should accept a doublel 1 as input. The readTemps method should create and return a doublel 1 and does not take any arguments. The other three should accept a doublel ] as input and return a double value. Make sure you test your program using temperatures bpth above and below zero. Temperatures that you output should be formatted to display 2 places past the decimal point. Sample run: Enter the number of temperatures: 7 Please enter 7 temperatures... Enter temperature #1 of 7: 77 Enter temperature #2 of 7: 65 Enter temperature #3 of 7: 69 Enter temperature #4 of 7: 82 Enter temperature #5 of 7: 70 Enter temperature #6 of 7: 57 Enter temperature #7 of 7: 76 The average temperature is 70.86 The highest temperature is 82.00 The lowest temperature is 57.00 The above statistics are based on the following temperatures: Temperature #1: 77.00 Temperature #2: 65.00 Temperature #3: 69.00 Temperature #4 : 82.00 Temperature #5: 70.00 Temperature #6: 57.00 Temperature 17: 76.00
media%2F331%2F3311dc81-b025-4959-8fef-84
media%2Fdf2%2Fdf23d1c5-5529-4bc1-a8be-de
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

import java.util.Scanner;

public class Temperatures{

public static void main(String[] args) {

double[] Temperature = readTemps();

System.out.printf("\nThe average is %.2f%n", averageTemps(Temperature));

highestTemps(Temperature);

lowestTemps(Temperature);

System.out.println("\nThe above statistics are based on the following temperatures: ");

printTemps(Temperature);

}

private static double[] readTemps(){

Scanner keyboard = new Scanner(System.in);

System.out.printf("Enter the number of temperatures: ");

int numTemps = keyboard.nextInt();

double[] Temps = new double[numTemps];

System.out.println("Please enter "+Temps.length+" Temperatures: ");

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

System.out.print("Enter grade #"+(i+1)+" of "+Temps.length+": ");

Temps[i] = keyboard.nextDouble();

}

return Temps;

}

public static double averageTemps(double[] numbers){

double sum = 0.0;

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

sum = sum+numbers[i];

}

return sum/numbers.length;

}

private static void printTemps(double[] numbers){

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

System.out.printf("Grade #"+(i+1)+": %.2f\n",numbers[i]);

}

}

private static void highestTemps(double[] numbers){

double highest = Double.MIN_VALUE;

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

if(numbers[i]>highest){

highest = numbers[i];

}

}

System.out.printf("The highest temperature is %.2f\n",highest);

}

private static void lowestTemps(double[] numbers){

double lowest = Double.MAX_VALUE;

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

if(numbers[i]<lowest){

lowest = numbers[i];

}

}

System.out.printf("The lowest temperature is %.2f\n",lowest);

}

}

Add a comment
Know the answer?
Add Answer to:
Please help my finish problem 1. Please edit my coding (shown below) about the highestTemps and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

  • This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...

    This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...

  • The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...

    The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2; The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical. The program is as follows: Ch. 11, Assignment #3. pg. 646. Program #4. //Weather Statistics. //Write a program that uses a structure to store the...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Problem 7. Stock Market For this program you are given a String that represents stock prices...

    Problem 7. Stock Market For this program you are given a String that represents stock prices for a particular com- y over a period of time. For example, you may be given a String that looks like the following: String stockPrices = "1,22,30,38,44,68,49,73,52,66"; Each number in this String represents the stock price for a particular day. The first number is day 0, the second number is day 1, and so on. You can al supplied string will formatted using commas...

  • PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from...

    PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods....

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • this is a java course class. Please, I need full an accurate answer. Labeled steps of...

    this is a java course class. Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with: (Create another file to test the class and output to the screen, not an output file) please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer. Thanks in advance. Write the definition of the class Tests such...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT