Answer to Question #230889 in Java | JSP | JSF for Samuel

Question #230889

Flow control is one of the main building blocks that determines how a program should run. Ghana Cocoa Growing company wishes to compare the impart of two newly acquired fertilizers on cocoa. They will do this by applying the same quantity of the two fertilizers on two similar but different cocoa plant under the same conditions (humidity, sunlight, soil moisture etc.). They will then choose the fertilizer whose crop produces the best harvest (highest quantity per square feet). As a programmer, 

c. create a method that takes four arguments i.e. (the names of the two fertilizer and their individual yields). The methods should return the name of the fertilizer with the greatest yield.  

    

d. Using “c” above, write a program that request for two fertilizer name and their respective yields. Your program should display the fertilizer with the most yield   

e. Discuss your answer in “d” above


1
Expert's answer
2021-08-30T01:36:05-0400
import java.util.Scanner;

public class Main {
    public static String findBetter(String fertilizerNameOne, String fertilizerNameTwo,
                                    int yieldOne, int yieldTwo) {
        return yieldOne >= yieldTwo ? fertilizerNameOne : fertilizerNameTwo;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the fertilizer name: ");
        String fertilizerNameOne = in.nextLine();
        System.out.print("Enter the yield: ");
        int yieldOne = Integer.parseInt(in.nextLine());
        System.out.print("Enter the fertilizer name: ");
        String fertilizerNameTwo = in.nextLine();
        System.out.print("Enter the yield: ");
        int yieldTwo = Integer.parseInt(in.nextLine());
        System.out.println("The better one: " + findBetter(fertilizerNameOne, fertilizerNameTwo, yieldOne, yieldTwo));
    }
}


Read data -> Call the method and pass the read data to it -> Show result


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS