Code the problem using a main method plus two additional met
Code the problem using a main() method plus two additional methods.
Use the names fvFor() and fvWhile() as your method names.
Refer to the flow chart on void methods for guidance.
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.
Pass both arguments to the method as numeric literals.
Design and code the fvFor() method to receive the two parameters.
Use the two parameters to govern a for loop within the method. You may need one or more additional local variables within the method.
Inside the body of the for loop, perform whatever calculations are needed and display the output, one line for each iteration of the loop.
When the for loop completes, return control to main().
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.
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.
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.
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 chart that shows how many milligrams of sodium chloride to add to a volume of water, measured in milliliters, to achieve a 3% solution. The range to include for liquid volume: 100 milliliters to 2000 milliliters in 100 milliliter increments. If you’re lazy and don’t want to read a chemistry book, some helpful search terms for Google: “making salt solutions 3%” If you are really lazy, read number 6 at http://www.mgel.msstate.edu/pdf/solutions.pdf
100 milliliters: 3.00 grams
 …
 2000 milliliters: 60.00 grams
would need this is java
Solution
AddNaclToWater.java
import java.util.Scanner;
public class AddNaclToWater {
   public static void main(String[] args) {
        //Declaring variables
        int lower,upper;
       
        //Scanner class object is used to read the inputs entered by the user
        Scanner sc=new Scanner(System.in);
       
        /* This loop continues to execute Until
        * the user enters valid number for lower value
        */
        while(true)
        {
        //Getting tye lower value entered by the user
        System.out.print(\"Enter the Lower Limit value(>=100) :\");
        lower=sc.nextInt();
       
        /* Checking whether is less than 100 or not.
        * If less than 100.display error message and prompt user to enter again
        */
        if(lower<100)
        {
            System.out.println(\":: Invalid Value.Must be greater than or equal to 100 ::\");
            continue;
        }
        else
            break;
        }
       
       /* This loop continues to execute Until
        * the user enters valid number for upper value
        */
        while(true)
        {
        System.out.print(\"Enter the Upper Limit value(<=2000) :\");
        upper=sc.nextInt();
       
        /* Checking whether is greater than 2000 or not.
        * If yes greater than 2000.display error message and prompt user to enter again
        */
        if(upper>=2000)
        {
            System.out.println(\":: Invalid Value.Must be Less than or equal to 2000 ::\");
            continue;
        }
        //checking whether the upper is less than lower
        else if(upper<lower)
            {
            System.out.println(\":: Invalid Value.Upper value must be greater tha lower value ::\");
        continue;
            }
        else
            break;
        }
       
    
        System.out.println(\"______Calling fvFor() Method_____\");
        //Calling the method fvFor()
        fvFor(100,2000);
        System.out.println(\"\ ______Calling fvWhile() Method_____\");
        //Calling the method fvWhile()
        fvWhile(100,2000);
    }
  
    private static void fvWhile(int lower, int upper) {
        int i=lower;
        while(i<=upper)
        {
            System.out.println(i+\" milliliters :\"+ (i/100)*3+\" grams\");
            i+=100;
        }
       
    }
   private static void fvFor(int lower, int upper) {
        for(int i=lower;i<=upper;i+=100)
        {
            System.out.println(i+\" milliliters :\"+ (i/100)*3+\" grams\");
        }
    }
}
_____________________________________
Output:
Enter the Lower Limit value(>=100) :50
 :: Invalid Value.Must be greater than or equal to 100 ::
 Enter the Lower Limit value(>=100) :100
 Enter the Upper Limit value(<=2000) :2100
 :: Invalid Value.Must be Less than or equal to 2000 ::
 Enter the Upper Limit value(<=2000) :200
 ______Calling fvFor() Method_____
 100 milliliters :3 grams
 200 milliliters :6 grams
 300 milliliters :9 grams
 400 milliliters :12 grams
 500 milliliters :15 grams
 600 milliliters :18 grams
 700 milliliters :21 grams
 800 milliliters :24 grams
 900 milliliters :27 grams
 1000 milliliters :30 grams
 1100 milliliters :33 grams
 1200 milliliters :36 grams
 1300 milliliters :39 grams
 1400 milliliters :42 grams
 1500 milliliters :45 grams
 1600 milliliters :48 grams
 1700 milliliters :51 grams
 1800 milliliters :54 grams
 1900 milliliters :57 grams
 2000 milliliters :60 grams
______Calling fvWhile() Method_____
 100 milliliters :3 grams
 200 milliliters :6 grams
 300 milliliters :9 grams
 400 milliliters :12 grams
 500 milliliters :15 grams
 600 milliliters :18 grams
 700 milliliters :21 grams
 800 milliliters :24 grams
 900 milliliters :27 grams
 1000 milliliters :30 grams
 1100 milliliters :33 grams
 1200 milliliters :36 grams
 1300 milliliters :39 grams
 1400 milliliters :42 grams
 1500 milliliters :45 grams
 1600 milliliters :48 grams
 1700 milliliters :51 grams
 1800 milliliters :54 grams
 1900 milliliters :57 grams
 2000 milliliters :60 grams
_________________Thank You




