根据父母输入查找孩子的身高。 Java的

时间:2018-04-08 01:02:53

标签: java height inches

好的,所以我一直试图在java中制作一个程序,根据父母身高(英尺/英寸)计算孩子的身高,并根据用户输入的性别来估计答案。虽然我已经被困了好几个小时了。似乎我没有尝试做正确的计算。我是java新手,第2周...我觉得这应该很容易吗?也许我从中获得了比它需要更多的东西?

添加了我的程序在完成后应该如何显示的图片。

(( Example of how the output needs to look. ))

public static void main(String[] args) 
{
Scanner scan = new Scanner(System.in);

String userChoice;
int heightMom, heightDad, FemaleChildh, MaleChildh, genderChild;

System.out.println("Enter the gender of your future child. Use 1 for female, 
0 for male.");
genderChild = scan.nextInt();

System.out.println("Enter the height in feet, then the height in inches of 
the mom.");
heightMom = scan.nextInt();

System.out.println("Enter the height in feet, then the height in inches of 
the dad.");
heightDad = scan.nextInt();

MaleChildh = (heightMom*13/12 + heightDad)/2;
FemaleChildh = (heightDad+12/13 + heightMom)/2;

if (genderChild.equals(1))
System.out.println(("Your future child is estimated to grow 
to")+FemaleChildh);

if (genderChild.equals(0))
System.out.println(("Your future child is estimaed to grow to")+MaleChildh);

System.out.println("Enter 'Y' to run again, anything else to exit.");
userChoice = scan.next();
if (userChoice.equals("Y"))
System.out.println("Continuing...");
else if (userChoice.equals(""))
break;
}

1 个答案:

答案 0 :(得分:0)

将heightmom和heightdad分隔成英尺和英寸。 使用双打来存储您的MaleChildh和FemaleChildh。 用'估计'这个词修正拼写错误。

编辑:看看你是否理解这段代码,然后将英寸部分添加到孩子的身高。

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    String userChoice;
    int heightMomFt, heightMomIn, heightDadFt, heightDadIn, genderChild;
    double FemaleChildhFt, MaleChildhFt, FemaleChildhIn, MaleChildhIn;
    while (true) {
        System.out.println("Enter the gender of your future child. Use 1 for female, 0 for male.");
        genderChild = scan.nextInt();

        System.out.println("Enter the height in feet, then the height in inches of the mom.");
        heightMomFt = scan.nextInt();
        heightMomIn = scan.nextInt();

        System.out.println("Enter the height in feet, then the height in inches of the dad.");
        heightDadFt = scan.nextInt();
        heightDadIn = scan.nextInt();

        MaleChildhFt = (heightMomFt * 13 / 12 + heightDadFt) / 2;
        FemaleChildhFt = (heightDadFt + 12 / 13 + heightMomFt) / 2;

        if (genderChild == 1)
            System.out.println(("Your future child is estimated to grow to") + FemaleChildhFt);

        if (genderChild == 0)
            System.out.println(("Your future child is estimated to grow to") + MaleChildhFt);

        System.out.println("Enter 'Y' to run again, anything else to exit.");
        userChoice = scan.next();
        if (userChoice.equals("Y"))
            System.out.println("Continuing...");
        else
            break;
    }
}