Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Hello how do I add data validation for this

Hello how do I add data validation for this?

import java.util.Scanner;

/**

 *

 * @author snhu.edu

 */

public class MileStone1_IngredientClass {

  /**

   * @param args the command line arguments

   */

  public static void main(String[] args) {

    String nameOfIngredient = “”;            //assignment of variables

    float ingredientAmount = 0.0f;

    String unitMeasurement = “”;

    int numberCaloriesPerUnit = 0;

    float totalCalories = 0.0f;

    Scanner scnr = new Scanner(System.in);

    System.out.println(“Please enter the name of the ingredient: “); 

    nameOfIngredient = scnr.next();           //prompting user to input the name of the ingredient

    System.out.println(“Please enter the amount of ” 

    + nameOfIngredient + ” we’ll need: “);

    ingredientAmount = scnr.nextFloat();         //prompting user to input the ingredient amount

    System.out.println(“Please enter the unit of measurement “);

    unitMeasurement = scnr.next();            //asking user to input the measurement amount

    System.out.println(“Please enter the number of calories per unit: “);

    numberCaloriesPerUnit = scnr.nextInt();       // prompting user to enter the number of calories per cup

    totalCalories = ingredientAmount * numberCaloriesPerUnit;

                              // expression to calculate the total calories assigned to totalCalories

    System.out.println(nameOfIngredient + ” uses ” + ingredientAmount 

    + ” and has ” + totalCalories + ” calories.”);

  }

/**

 * 

 * For your Final Project, adapt your Ingredient java file to include

 * data type validation steps for each of the variables in the class:

 * 

 * ingredientName (String)

 * ingredientAmount (float)

 * unitMeasurment (String)

 * number of Calories (double)

 * 

 
"Looking for a Similar Assignment? Order now and Get 10% Discount! Use Code "Newclient"