I'm working on a workshop for my JAVA. There's one part I'm having difficulty understanding: Apply the following formulas based on gender (must use an if statement(s)): Hmale_child = ((Hmother * 13/12) + Hfather)/2 OR Hfemale_child = ((Hfather * 12/13) + Hmother)/2
How do I use an if statement with these formulas? I use the Hmale_child if the user inputs that their child's gender is male. But all the if statements I've seen have to do with numbers. Can anyone point me in the right direction?
Something like: if (gender == male) ??
import java.util.Scanner;
public class WKSP6Trial
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner(System.in);
Scanner inp = new Scanner(System.in);
String Letter;
String input = "";
String exit = "exit";
boolean isStringLetter = true;
System.out.println("Welcome! If at any time you wish to exit the program, type the word exit, and press enter.");
while(true)
{
System.out.println("\nPlease enter letters m or f only as you enter your child's gender: ");
input = inp.nextLine();
if(input.equalsIgnoreCase(exit)){break;}
isStringLetter = input.matches("[m/f/M/F]+");
if(isStringLetter == false)
{
System.out.println("\nYou entered a non letter " + input);
System.out.println("Remove all non letters aside from m or f from your input and try again !");
break;
}
System.out.println("You entered the gender of your child.");
System.out.println("Next enter the height of the child's father in feet followed by ");
System.out.println("the father's height in inches: ");
int n1, n2;
n1 = scannerObject.nextInt();
n2 = scannerObject.nextInt();
System.out.println("You entered " + n1 + " followed by " + n2);
System.out.println("Finally, enter the height of the child's mother followed by ");
System.out.println("the mother's height in inches: ");
int d1, d2;
d1 = scannerObject.nextInt();
d2 = scannerObject.nextInt();
System.out.println("You entered " + d1 + " followed by " + d2);
Scanner in = new Scanner(System.in);
System.out.print("Convert from: ");
String fromUnit = in.nextLine();
System.out.print("Convert to: ");
String toUnit = in.nextLine();
//below is what I'm uncertain of
if(gender == m)
Hmale_child = ((Hmother * 13/12) + Hfather)/2;
}
}
}