Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Martians wants a program to help them analyze the soil on Mars. They want to determine the best areas to grow crops. You will

image text in transcribed imageimage

Martians wants a program to help them analyze the soil on Mars. They want to determine the best areas to grow crops. You will write a program that will accept, at the command line, two Strings, one containing various soil composition elements and another containing the values found of these elements within the soil samples. A sample of the two Strings are below: carbon-dioxide, magnesium, sodium, potassium chloride,water 8.3,4,5,6.7.2.3,12.5.4.53.9,1.8,34.723.5,1.2,14.3 6.7.7.4,1.5,18.4.7.2.23.7 23.4.5. 6,2.9,18.5,39.5,18.2 15.4.5.3,27 4,9.8.3.8,27.4 The elements in the first string are separated by a "," character. The compositions found in the second string are separated into a two-dimensional grid with the rows separated by the " " characters and each column separated by a "," character. MoonSamples.java will contain several methods. The first method is the getElements() method. This method takes in a String of elements and returns a one-dimensional String array containing the list of elements. You can use the String method .split(",") to split your string based on the "," character separating the categories. Here is the method header. public static String [] getElements (String inputElement String) { //Your code here } The second method is the getSamples() method. This method takes in a String of sample values and returns a two-dimensional double array containing the elemental composition of each sample. Again, you can use the String method .split("String") to split your string based on the char character you specify. You will need to split this string on the "," and ">" symbols. Here is the method header. public static double [] [] getSamples (String inputsamplesString) { //Your code here } Here is an example of the two arrays that are created from the first two methods. Note the two- dimensional array will just contain the sample values. This is just an example of the data that might be used to test your code. The elements and their order will not change. However, the samples will change, but will always be numerically labeled starting with the number 1. Sample 1 2 3 4 5 carbon dioxide carbon dioxide 8.3 3.9 6.7 23.4 15.4 magnesium sodium potassium chloride water magnesium sodium potassium chloride water 6.7 12.5 4.5 34.7 1.2 14.3 1.5 7.2 23.7 2.9 39.5 18.2 27.4 3.8 27.4 4.5 1.8 7.4 5.6 5.3 2.3 23.5 18.4 18.5 9.8 The third method is searchForLife(). This method takes in a 2D double array of sample values. It will search all samples for the ones that could support life. The formula for supporting life is as follows: formula for life = (8 carbon dioxide) + (2. magnesium) +sodium + (4. potassium) + chloride + (5. water) } The criteria value that needs to be attained is: 300. If this criteria value is attained or surpassed, then the sample number is returned in an int array. If the first row of data attains the score of 300 or more, the number 1 will be inserted into the first position in the int array. Since not all samples may meet the criteria, the array returned should be resized so that it only contains the values that meet the criteria with no extra data. public static int[] searchForLife (double [] [] samples) { //Your code here } The fourth method is searchHighestElements (). This method will take in a String array of elements, a 2D double array of sample values, and a sample to search. It will search that sample and will return a string containing the two elements that are found in the highest amount for that sample in the order of highest first, then second highest element. public static String searchHighestElements (double [][] samples, Sring [] elements, int sampleNum) { //Your code here The fifth method is search HighestSample(). This method will take in a String array of elements, a 2D double array of sample values, and an element to search. It will search for and return the sample number that contains the highest amount of that element. public static int searchHighestSample (double [][] samples, String [] elements, String element) { //Your code here } Lastly, you will define a main method. The main method will do the following: Accept, at the command line, two Strings, one containing various soil composition elements and another containing the values found of these elements within the soil samples Pass the first command line argument to the getElements() method and store the result Pass the second command line argument to the getSamples() method and store the result Call searchForLife(), passing in the result of getSamples() and print the result Call searchHighestElements(), passing in the results of getSamples() and getElements() and print the result Call searchHighestSample(), passing in the results of getSamples() and getElements() and print the result The main method will not be tested by the test cases. You should use your own output statements to test the output of your code based on the inputs given. Below is a sample run: The samples that contain life are: 4 5 The highest elements for sample 1 are chloride and carbon- dioxide The sample with the highest value of the element water is 5 You can assume all arguments passed in on the command line are valid Strings for this program. Before beginning this project, you will document your algorithm as a list of steps to take you from your inputs to your outputs. This algorithm will be due on paper at the beginning of class on the day it is due. This will be graded and returned to you. It will be your responsibility to understand and correct any errors you might have with your algorithm. Each step will be added as a comment block within your code. You will have the comment block right above the code that performs the actions specified. For example, before your lines of code that ask the user for inputs, you would have a comment block that states what inputs you are requesting from the user.

Step by Step Solution

3.41 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

Certainly Heres the implementation of the getElements and getSamples methods in the MoonSamples Java ... 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

Fundamentals of Cost Accounting

Authors: William Lanen, Shannon Anderson, Michael Maher

3rd Edition

9780078025525, 9780077517359, 77517350, 978-0077398194

More Books

Students also viewed these Programming questions