Question

Java --- Write a method to summarise daily tempratures. The details are given as follow. -...

Java ---

Write a method to summarise daily tempratures. The details are given as follow.

- The method will receive an array of doubles. Each number in the array represents the temperature of a day.

- If there are less than 10 temperatures recorded, the method will not perform any calculation. Instead, it will print a message "Insufficient data".

- If there are 10 or more temperature recorded, the method will calculate:

-- the average temperature

-- the highest temperature

-- the number of cool days in which the temperatures are 20 or below

-- the number of warm days in which the temperatures are 21 to 30 (inclusive)

-- the number of hot days in which the temperatures are 31 and above.

- Upon completion, the method will print the following:

-- the number of cool days

-- the number of warm days

-- the number of hot days

-- the average temperature

-- the highest temperature

You may assume the array is not empty. You can make use of the following code snippet to write your answer:

---------------------------------------------

public static void getSummary (double [ ] temperatures)

{

//write your code here

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// I write entire program to check its working...

// you can only copy the function u need...

// it is written according to ur need ...

public class temp{
   public static void main(String args[]){
       double arr[] = {1,2,3,4,5,6,7,8,9,13};
       getSummary(arr);
  
   }
   public static void getSummary (double[] temperatures){
      
       int length = temperatures.length;
       if(length < 10){
           System.out.println("Insufficient data");return ;
       }
       double t,highest = temperatures[0]; // assume first one is highest initially;
       int avg = 0;
       int cool_days = 0,hot_days = 0,warm_days = 0,index; // initial values are 0's
       for(index = 0;index < length ;index ++){
           t = temperatures[index];
           avg += t ;
           if(t > highest) highest = t ;
           if(t <= 20) cool_days ++;
           else if(t <= 30)warm_days ++;
           else hot_days ++;  
       }
       System.out.println(" the number of cool days = "+cool_days+" \n the number of warm days = "+warm_days + " \n the number of hot days = "+hot_days +" \n the average temperature = "+avg/(float)length + "\n the highest temperature = "+highest);

   }
}

Add a comment
Know the answer?
Add Answer to:
Java --- Write a method to summarise daily tempratures. The details are given as follow. -...
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
  • looking for in Java Write the method loadArray. The method will declare and open a file...

    looking for in Java Write the method loadArray. The method will declare and open a file stream and connect it to the external file passed in. It will then read patient names into the patients array and their temperatures into the temps array. The method should compute/determine the number of patients in the file. Make sure you do all steps of file VO] A sample file, and some declarations and a sample function call are given Sample File Mickey 102.5...

  • Write a Java program that has a method called arrayAverage that accepts an arrary of numbers...

    Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output:

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • java pseudocode and source code help? Write a program that uses an array of high temperatures...

    java pseudocode and source code help? Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array...

  • Write a method that asks the user to enter a list of names and ages using...

    Write a method that asks the user to enter a list of names and ages using Gui input and splits the info into an array of String. Validate that every other string is an int and check the value to ensure it is between 21 and 65 inclusive, print a message to the standard error object if not. Return the array. Use regular expressions to split and validate. Must follow java conventions and indent. In java with good indentations please

  • java programming!!! Write the code fragment that will do the following: • Ask the user how...

    java programming!!! Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and...

    IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array.   Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code.   Your program should output...

  • Java Code Help! Code this: Calculate statistics. Write a class called Statistics that can calculate a...

    Java Code Help! Code this: Calculate statistics. Write a class called Statistics that can calculate a number of properties about an array of doubles. There should be separate static methods to calculate the min, the max, the mean, the median, the standard deviation (make sure to make use of your mean method to implement this), and the mode. For the mode, you can assume that the data set is not multimodal. This class should not have a main method. Write...

  • In Java, write a method which, given an array of Strings and a char as the...

    In Java, write a method which, given an array of Strings and a char as the parameters, will find the number of Strings which contained that char (in any position). The method will return that number back to the main program

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
ADVERTISEMENT