Question

Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods t
java pseudocode and source code help?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Created methods with appropriate comments are given for your understanding in the below code.

CODE:

package temperature;
public class Temperature {
//Method to find the minimum temperature.
public static double lowHighTemperature(double temperature[])
{
double min;
//Assigning maximum value of double to variable min so as to make comparison of minimum easy.
//Because any double value will going to be less than it's maximum value.
min = Double.MAX_VALUE;
//for-each loop to find the minimum temperature.
for(double i: temperature){
if(i<min)
min = i;
}
//returning the minimum temperature.
return min;
}
//Method to find the maximum temperature.
public static double highestHighTemperature(double temperature[])
{
double max;
//Assigning minimum value of double to variable max so as to make comparison of maximum easy.
//Because any double value will going to be greater than it's minimum value.
max = Double.MIN_VALUE;
//for-each loop to find the maximum temperature.
for(double i: temperature){
if(i>max)
max = i;
}
//returning the maximum value.
return max;
}
//Method to add 10 to each element of the array and returning that modified arrya.
public static double[] addTemperature(double temperature[])
{
for(int i=0;i<temperature.length;i++)
temperature[i] += 10;
return temperature;
}
public static void main(String[] args) {
//Initializig the temperature with temperature of the 7 days of week.
double temperature[] = {30.5,20.5,22.5,23,40.5,15.5,35};
//Calling the appropriate function to return the lowest temperature
//of last 7 days and assiging it to a minTemp variable.
double minTemp = lowHighTemperature(temperature);
//Calling the appropriate function to return the highest temperature of
//the last 7 days and assigning it to maxTemp variable.
double maxTemp = highestHighTemperature(temperature);
//Calling the appropriate function to add 10 to each element of the array
//and returned value is assigned to newTemperature array.
double newTemperature[] = addTemperature(temperature);
//Printing the returned values
System.out.println("The minimum temperature of the last 7 days is:"+minTemp);
System.out.println("The maximum temperature of the last 7 days is:"+maxTemp);
System.out.println("The temperature array after adding 10 to each temperature is:");
for(int i=0;i<newTemperature.length;i++)
System.out.print(newTemperature[i]+" ");
}
  
}

CODE SCREENSHOT:

package temperature; public class Temperature { //Method to find the minimum temperature. public static double lowHighTemperapublic static void main (String[] args) { //Initializig the temperature with temperature of the 7 days of week. double temper

CODE OUTPUT:

run: The minimum temperature of the last 7 days is:15.5 The maximum temperature of the last 7 days is:40.5 The temperature ar

Add a comment
Know the answer?
Add Answer to:
java pseudocode and source code help? Write a program that uses an array of high temperatures...
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
  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name...

    PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students’ grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a...

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • Java Program: Write an algorithm (steps) using pseudocode (no java code required) explaining steps for a...

    Java Program: Write an algorithm (steps) using pseudocode (no java code required) explaining steps for a method which will reverse an integer array (Integer[]) without using any other data structure. The method should return the reversed integer array. E.g. If input array Integer[] integers = [1,2,3,4,5,6] should return [6,5,4,3,2,1]

  • In Java write the following array- processing methods into the same application, Lab13.java. Use the main...

    In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...

  • 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...

  • In JAVA Create a program with an array with the following data: 50 12 31 76...

    In JAVA Create a program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - highest to lowest. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.  

  • In java, write method, shuffle, which accepts an array of int, creates a copy of the...

    In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...

  • Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1...

    Using JAVA, write an application that uses an Array of 30 Numbers (random integers from 1 - 100) and returns the maximum number, minimum number, average of all numbers, and prints a Bar Chart to show the number distribution (1-9, 10-19,20-29, …80-89, 90-100). Note; maximum number, minimum number, average number, and the Bar Chart must use implemented as separate methods in a separate class. Method call should pass an array as an argument. Methods should accept an array as an...

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