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,
a. Suggest a flow control method that would be used to do the comparison and explain the reason why you chose it.
b. Write a flow control statement that would do the comparison in “a” above.
a.
Using decision making statements. It will compare the fertilizer with the best harvest.
b.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int f1 ;
int f2 ;
System.out.println("Enter highest quantity per square feet of the first fertilizer:");
f1=in.nextInt();
System.out.println("Enter highest quantity per square feet of the second fertilizer:");
f2=in.nextInt();
if(f1>f2) {
System.out.println("The first fertilizer is the best");
}
else {
System.out.println("The second fertilizer is the best");
}
}
}
Comments
Leave a comment