subject
Engineering, 26.02.2021 20:10 jumana3

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

The ExperimentalFarm class represents crops grown on an experimental farm. An experimental farm is a rectangular tract of land that is divided into a grid of equal-sized plots. Each plot in the grid contains one type of crop. The crop yield of each plot is measured in bushels per acre.

A farm plot is represented by the Plot class. A partial definition of the Plot class is shown below.

public class Plot

{

private String cropType;

private int cropYield;

public Plot(String crop, int yield)

{

/* implementation not shown */

}

public String getCropType()

{

return cropType;

}

public int getCropYield()

{

return cropYield;

}

}

The grid of equal-sized plots is represented by a two-dimensional array of Plot objects named farmPlots, declared in the ExperimentalFarm class. A partial definition of the ExperimentalFarm class is shown below.

public class ExperimentalFarm

{

private Plot[][] farmPlots;

public ExperimentalFarm(Plot[][] p)

{

/* implementation not shown */

}

/** Returns the plot with the highest yield for a given crop type, as described in part (a). */

public Plot getHighestYield(String c)

{

/* to be implemented in part (a) */

}

/** Returns true if all plots in a given column in the two-dimensional array farmPlots

* contain the same type of crop, or false otherwise, as described in part (b).

*/

public boolean sameCrop(int col)

{

/* to be implemented in part (b) */

}

}

(a) Write the getHighestYield method, which returns the Plot object with the highest yield among the plots in farmPlots with the crop type specified by the parameter c. If more than one plot has the highest yield, any of these plots may be returned. If no plot exists containing the specified type of crop, the method returns null.

Assume that the ExperimentalFarm object f has been created such that its farmPlots array contains the following cropType and cropYield values.

The figure presents a two-dimensional array of Plot objects with 3 columns and 4 rows. The columns are labeled from 0 to 2, and the rows are labeled from 0 to 3. Each plot is labeled with a crop name and crop yield as follows. Row 0. Column 0, "Corn" 20. Column 1, "Corn" 30. Column 2, "Peas" 10. Row 1. Column 0, "Peas" 30. Column 1, "Corn" 40. Column 2, "Corn" 62. Row 2. Column 0, "Wheat" 10. Column 1, "Corn" 50. Column 2, "Rice" 30. Row 3. Column 0, "Corn" 55, Column 1, "Corn" 30. Column 2, "Peas" 30.
The following are some examples of the behavior of the getHighestYield method.

Method Call Return Value
f. getHighestYield("corn") ​farmPlots[1][3]
f. getHighestYield("peas") farmPlots[1][0] or farmPlots[3][2]​
f. getHighestYield("bananas") null
Write the getHighestYield method below.

/** Returns the plot with the highest yield for a given crop type, as described in part (a). */

public Plot getHighestYield(String c)

(b) Write the sameCrop method, which returns true if all the plots in a given column of farmPlots grow the same crop and returns false otherwise.

Assume that the ExperimentalFarm object f has been created such that its farmPlots array contains the following cropType and cropYield values.

The figure presents a two-dimensional array of Plot objects with 3 columns and 4 rows. The columns are labeled from 0 to 2, and the rows are labeled from 0 to 3. Each plot is labeled with a crop name and crop yield as follows. Row 0. Column 0, "Corn" 20. Column 1, "Corn" 30. Column 2, "Peas" 10. Row 1. Column 0, "Peas" 30. Column 1, "Corn" 40. Column 2, "Corn" 62. Row 2. Column 0, "Wheat" 10. Column 1, "Corn" 50. Column 2, "Rice" 30. Row 3. Column 0, "Corn" 55, Column 1, "Corn" 30. Column 2, "Peas" 30.
The following are two examples of the behavior of sameCrop.

The method call f. sameCrop(0) returns false because the values of cropType for the elements of column 0 ("corn", "peas", "wheat", and "corn") are not all the same.
The method call f. sameCrop(1) returns true because the values of cropType for all elements of column 1 are the same ("corn").
Write the sameCrop method below.

/** Returns true if all plots in a given column in the two-dimensional array farmPlots

* contain the same type of crop, or false otherwise, as described in part (b).

*/

public boolean sameCrop(int col)

ansver
Answers: 2

Another question on Engineering

question
Engineering, 04.07.2019 18:10
What difference(s) did you notice using a pneumatic circuit over hydraulic circuit.explain why the pneumatic piston stumbles when it hits an obstacle.
Answers: 2
question
Engineering, 04.07.2019 18:10
Aflywheel accelerates for 5 seconds at 2 rad/s2 from a speed of 20 rpm. determine the total number of revolutions of the flywheel during the period of its acceleration. a.5.65 b.8.43 c. 723 d.6.86
Answers: 2
question
Engineering, 04.07.2019 18:10
Afull journal bearing has a journal diameter of 27 mm, with a unilateral tolerance of -0.028 mm. the bushing bore has a diameter of 27.028 mm and a unilateral tolerance of 0.04 mm. the l/d ratio is 0.5. the load is 1.3 kn and the journal runs at 1200 rev/min. if the average viscosity is 50 mpa-s, find the minimum film thickness, the power loss, and the side flow for the minimum clearance assembly.
Answers: 1
question
Engineering, 04.07.2019 18:10
The higher the astm grain-size number, the coarser the grain is. a)-true b)-false
Answers: 3
You know the right answer?
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the class...
Questions
question
Mathematics, 23.02.2021 02:00
question
Biology, 23.02.2021 02:00
Questions on the website: 13722360