Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a java program Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The

write a java program

Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The an object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where arrays can be used. After the topic of arrays has been covered create arrays of class Temperature. Write a program that satisfies the next 6 requirements using Temperatures. Create a class similar to the Math class. Put the next 5 static methods in it. (These static methods could also be in the Demo class.) On my website are two example programs that demonstrate passing arrays and returning arrays: Passing Arrays using static methods and ChangeArgumentDemo. Use the random number generator as described on the bottom of page 412 to create 3 arrays of random sizes of 1 to 5 elements.

  1. Create a static void method that has an array parameter and is called 3 times to read in Temperature values for each array.
  2. Create a static method that computes and returns the average Temperature for each array and is also called 3 times.
  3. Create a static method that prints the Temperatures of an array.
  4. Create a static helper method that has 3 array parameters and either returns the largest array or the largest size.
  5. Create a static method that returns an array of Temperatures that has the same number of elements as the largest of the three arrays. This method will have 3 array parameters and possibly an integer parameter. It determines the largest Temperature value from the three arrays at each index and creates a copy of this Temperature and stores it at that index of the new array. This array is then returned.
  6. As this program is running it should generate user friendly text for input and output explaining what the program is doing.

Create a set of test value Temperatures that demonstrate that your program runs correctly. (My website gives sample output to follow.)

This the demo to use

public class TemperatureDemoWithArrays { public static void main(String[] args) { int x; Temperature average; System.out.println("You will be asked to fill 3 randomly sized arrays."); Temperature[] temperatureArrayOne; Temperature[] temperatureArrayTwo; Temperature[] temperatureArrayThree; temperatureArrayOne = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayOne); System.out.println("The values of temperature array one are "); printTemperatureArray(temperatureArrayOne); average = getAverage(temperatureArrayOne); System.out.println("The average of temperature array one is " + average); temperatureArrayTwo = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayTwo); System.out.println("The values of temperature array two are "); printTemperatureArray(temperatureArrayTwo); average = getAverage(temperatureArrayTwo); System.out.println("The average of temperature array two is " + average); temperatureArrayThree = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayThree); System.out.println("The values of temperature array three are "); printTemperatureArray(temperatureArrayThree); average = getAverage(temperatureArrayThree); System.out.println("The average of temperature array three is " + average); Temperature[] largest = getLargestArray(temperatureArrayOne, temperatureArrayTwo, temperatureArrayThree); Temperature[] arrayWithLargestValues1; if(temperatureArrayOne == largest) arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayTwo, temperatureArrayThree); else if(temperatureArrayTwo == largest) arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayThree); else// fractionArrayThree is largest arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayTwo); System.out.println(" Here are the temperatures in the three arrays:"); printTemperatureArray(temperatureArrayOne); printTemperatureArray(temperatureArrayTwo); printTemperatureArray(temperatureArrayThree); System.out.println(" An array with the largest values taken from the "+ "3 arrays has " + arrayWithLargestValues1.length + " elements."); System.out.println("This solution knew the largest array of the three arrays:"); printTemperatureArray(arrayWithLargestValues1); CODE THAT FOLLOWS IS A DIFFERENT ALGORITH THAT ALSO FINDS THE LARGEST ARRAY int sizeOfLargestArray = getSizezOfLargestArray(temperatureArrayOne, temperatureArrayTwo, temperatureArrayThree); Temperature[] arrayWithLargestValues = createArrayWithLargestValues(sizeOfLargestArray, temperatureArrayOne,temperatureArrayTwo, temperatureArrayThree); System.out.println(" An array with the largest values taken from the "+ "3 arrays has " + arrayWithLargestValues.length + " elements."); System.out.println("This solution knew the largest size of the three arrays:"); printTemperatureArray(arrayWithLargestValues); }//main

This is the out put of the program

You will be asked to fill 3 randomly sized arrays. This array has 1 temperature(s). please enter a temperature in this form 45 C 300 c The values of temperature array one are 300.0C The average of temperature array one is 300.0C This array has 4 temperature(s). please enter a temperature in this form 45 C 122 f please enter a temperature in this form 45 C 0 c please enter a temperature in this form 45 C 100 c please enter a temperature in this form 45 C 50 c The values of temperature array two are 122.0F, 0.0C, 100.0C, 50.0C The average of temperature array two is 122.0F This array has 3 temperature(s). please enter a temperature in this form 45 C 212 f please enter a temperature in this form 45 C 50 c please enter a temperature in this form 45 C 32 f The values of temperature array three are 212.0F, 50.0C, 32.0F The average of temperature array three is 122.0F Here are the temperatures in the three arrays: 300.0C 122.0F, 0.0C, 100.0C, 50.0C 212.0F, 50.0C, 32.0F An array with the largest values taken from the 3 arrays has 4 elements. This solution knew the largest array of the three arrays: 300.0C, 50.0C, 100.0C, 50.0C An array with the largest values taken from the 3 arrays has 4 elements. This solution knew the largest size of the three arrays: 300.0C, 50.0C, 100.0C, 50.0C 

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago