1Estimating the Adult Height of a Child Hmale_child = ((Hmotherx 13/12) + Hfathe
ID: 3536622 • Letter: 1
Question
1Estimating the Adult Height of a Child Hmale_child = ((Hmotherx 13/12) + Hfather)/2 Hfemale_child = ((Hfather x 12/13) +Hmother)/2 Using the formulas above, write a program that takes as INPUTthe gender of the child, the height of the mother in inches, andthe height of the father in inches, and outputs the estimated adultheight of the child in inches. Write appropriate methods as a part of the solution. The height of the child can not be zero. The program should allow the user to enter a new set of values and output the estimated height until the user decides to exit.Q2:- After creating the code in first one modify the code such that the gender and estimated adult height for each child are stores in appropriate arrays. Based upon the data in the array the program should then calculate and dsiplay the average height of male children and average height of female children.
Q3:- Modify the code in question 2 such that the gender and the estimated adult height data in the arrays is written to a text file. The name of the text file is to be obtained from the user. If the file already exists it should not be overwritten. Instead obtain a new filename from the user until the filename supplied form the user doesn't exist. Each line of text file should represent one child. the data on each line should be the gender followed by the estimated adult height.
I have the answer for the first one. Would any1 be able to continue on that and give me the answers for 2nd and third its very important.
Thanks Here is my code:-
import java.util.*;
public class height {
public static void main(String[] args) {
Scanner keyboard = newScanner(System.in);
//gender is treated as thesentinel.
int gender;
int HMother = 0, HFather =0;
System.out.println("Welcome,to exit the program enter -1 " +
" for the gender to quit.");
System.out.println("Pleaseenter the gender? (1 for male, 2 for female)");
gender =keyboard.nextInt();
while(gender != -1){
System.out.println("Enter the height of the mother.");
HMother =keyboard.nextInt();
System.out.println("Enter the height of the father.");
HFather =keyboard.nextInt();
if(gender== 1){
System.out.println("Height of male child: " +((HMother*(13/12)) + HFather)/2);
}else
System.out.println("Height of female child: " +((HFather*(12/13)) + HMother)/2);
System.out.println("Please enter the gender? (1 for male, 2 forfemale)");
gender =keyboard.nextInt();
}
}
}
1Estimating the Adult Height of a Child Hmale_child = ((Hmotherx 13/12) + Hfather)/2 Hfemale_child = ((Hfather x 12/13) +Hmother)/2 Using the formulas above, write a program that takes as INPUTthe gender of the child, the height of the mother in inches, andthe height of the father in inches, and outputs the estimated adultheight of the child in inches. Write appropriate methods as a part of the solution. The height of the child can not be zero. The program should allow the user to enter a new set of values and output the estimated height until the user decides to exit.
Q2:- After creating the code in first one modify the code such that the gender and estimated adult height for each child are stores in appropriate arrays. Based upon the data in the array the program should then calculate and dsiplay the average height of male children and average height of female children.
Q3:- Modify the code in question 2 such that the gender and the estimated adult height data in the arrays is written to a text file. The name of the text file is to be obtained from the user. If the file already exists it should not be overwritten. Instead obtain a new filename from the user until the filename supplied form the user doesn't exist. Each line of text file should represent one child. the data on each line should be the gender followed by the estimated adult height.
I have the answer for the first one. Would any1 be able to continue on that and give me the answers for 2nd and third its very important.
Thanks Here is my code:-
import java.util.*;
public class height {
public static void main(String[] args) {
Scanner keyboard = newScanner(System.in);
//gender is treated as thesentinel.
int gender;
int HMother = 0, HFather =0;
System.out.println("Welcome,to exit the program enter -1 " +
" for the gender to quit.");
System.out.println("Pleaseenter the gender? (1 for male, 2 for female)");
gender =keyboard.nextInt();
while(gender != -1){
System.out.println("Enter the height of the mother.");
HMother =keyboard.nextInt();
System.out.println("Enter the height of the father.");
HFather =keyboard.nextInt();
if(gender== 1){
System.out.println("Height of male child: " +((HMother*(13/12)) + HFather)/2);
}else
System.out.println("Height of female child: " +((HFather*(12/13)) + HMother)/2);
System.out.println("Please enter the gender? (1 for male, 2 forfemale)");
gender =keyboard.nextInt();
}
}
}
Explanation / Answer
Part(2)
import java.util.*;
class Mukesh {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
//gender is treated as thesentinel.
int gender[]=new int[1000];
float height[]=new float[1000];
float male_avg_height=0;
float female_avg_height=0;
int m=0;
int f=0;
int i=0;
int HMother = 0, HFather =0;
System.out.println("Welcome,to exit the program enter -1 " +
" for the gender to quit.");
System.out.println("Pleaseenter the gender? (1 for male, 2 for female)");
gender[0] =keyboard.nextInt();
while(gender[i] != -1)
{
System.out.println("Enter the height of the mother.");
HMother =keyboard.nextInt();
System.out.println("Enter the height of the father.");
HFather =keyboard.nextInt();
if(gender[i]== 1)
{
height[i]=((HMother*(13/12)) + HFather)/2;
male_avg_height=male_avg_height+height[i];
m++;
}
else
{
height[i]=((HFather*(12/13)) + HMother)/2;
female_avg_height=female_avg_height+height[i];
f++;
}
System.out.println("Please enter the gender? (1 for male, 2 forfemale)");
i++;
gender[i] =keyboard.nextInt();
}
if(f!=0)
{
System.out.println("Average height of female child: "+female_avg_height/f);
}
if(m!=0)
{
System.out.println("Average height of male child: "+male_avg_height/m);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.