in Java Code the problem using a main method plus two additi
in Java
Code the problem using a main() method plus two additional methods. C. Use the names fvFor() and fvWhile() as your method names. D. Refer to the flow chart on void methods for guidance. E. In the main() method, call the fvFor() method and pass it two arguments: the lower and upper boundaries in the range; these values are specified for each problem. F. Pass both arguments to the method as numeric literals. G. Design and code the fvFor() method to receive the two parameters. H. Use the two parameters to govern a for loop within the method. You may need one or more additional local variables within the method. I. Inside the body of the for loop, perform whatever calculations are needed and display the output, one line for each iteration of the loop. J. When the for loop completes, return control to main(). K. Once you have the fvFor() method working, then modify main() so it calls fvWhile(). Again, pass the two values representing the range as numeric literals, and have the method receive the parameters and produce the output. L. If all goes well, main will call each method, in sequence, and you will get the same output twice: once by the for loop version of the method, and the other with the while loop version. M. As a final step on this problem, adapt main() so that it\'s a little more flexible. Allow the user to specify the lower and upper boundaries from which to produce the chart. N. Use main() to validate the end user\'s input to ensure that each value (lower and upper boundary) fall within the \"reasonable\" range as noted in the problem. For anything outside of that range, display an error message and end the program.
A tip chart based 10%, 15%, and 20% rate. Bill range: $1 to $100 in increments of fifty cents. Bill $1.00: 10% = $.10; 15% = $.15; 20% = $.20 ... Bill $100.00: 10% = $10.00; 15% = $15.00; 20% = $20.00
Solution
Hi, Please find my code.
I am just displaying numbers in given range.
Please let me know in case of any issue.
import java.util.Scanner;
public class Program {
/* method that receives two int values and display all numbers in that range */
public static void fvFor(int lower, int upper){
// displaying all numbers in range using for loop
for(int i=lower; i<=upper; i++){
System.out.print(i+\" \");
}
}
/* method that receives two int values and display all numbers in that range */
public static void fvWhile(int lower, int upper){
// displaying all numbers in range using while loop
int i=lower;
while(i <= upper){
System.out.print(i+\" \");
i++;
}
}
// main method
public static void main(String[] args) {
// creating a Scanner Object to take user input
Scanner sc = new Scanner(System.in);
// taking user input for lower bound
System.out.print(\"Enter lower bound: \");
int lower = sc.nextInt();
System.out.print(\"Enter upper bound: \");
int upper = sc.nextInt();
// validating upper bound : upper bound should be greater than lower bound
while(lower >= upper){
System.out.print(\"Enter upper bound greater that \"+lower+\" :\");
upper = sc.nextInt();
}
// calling fvFor method
fvFor(lower, upper);
System.out.println();
// calling fvWhile method
fvWhile(lower, upper);
}
}
/*
Sample run:
Enter lower bound: 5
Enter upper bound: 12
5 6 7 8 9 10 11 12
5 6 7 8 9 10 11 12
*/


