-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ch3Ex3.java
78 lines (77 loc) · 2.68 KB
/
Ch3Ex3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Takes Inches or Feet of Parents as input
// and Estimates Child Height based on given equation
import java.util.Scanner;
public class Ch3Ex3
{
public static void main(String[] args)
{
String gender = "";
String unit = "";
Scanner input = new Scanner(System.in);
while (true)
{
int estimate = 0;
System.out.println("Enter 'quit' at anytime to exit!");
System.out.print("Enter 'boy' or 'girl': ");
gender = input.next();
if (gender.equals("quit"))
break;
System.out.print("Enter 'feet' or 'inches': ");
unit = input.next();
if (unit.equals("quit"))
break;
if (gender.equals("boy") && unit.equals("inches"))
{
System.out.print("Enter Mother Height in Inches :");
int heightMother = input.nextInt();
System.out.print("Enter Father Height in Inches :");
int heightFather = input.nextInt();
estimate = (((heightMother*13/12)+ heightFather)/2);
System.out.println("Estimated Child Height in Inches: "+ estimate);
}
else if (gender.equals("girl") && unit.equals("inches"))
{
System.out.print("Enter Mother Height in Inches :");
int heightMother = input.nextInt();
System.out.print("Enter Father Height in Inches :");
int heightFather = input.nextInt();
estimate = (((heightFather*12/13)+ heightMother)/2);
System.out.println("Estimated Child Height in Inches: "+estimate);
}
else if (gender.equals("boy") && unit.equals("feet"))
{
System.out.print("Enter Mother Height in Feet :");
int heightMother = 12* input.nextInt();
System.out.print("Enter Mother Height in Inches :");
heightMother += input.nextInt();
System.out.print("Enter Father Height in Feet :");
int heightFather = 12* input.nextInt();
System.out.print("Enter Father Height in Inches :");
heightFather += input.nextInt();
estimate = (((heightMother*13/12)+ heightFather)/2);
System.out.print("Estimated Child Height in Feet/Inches: ");
System.out.println((estimate/12)+"/"+(estimate%12));
}
else if (gender.equals("girl") && unit.equals("feet"))
{
System.out.print("Enter Mother Height in Feet :");
int heightMother = 12* input.nextInt();
System.out.print("Enter Mother Height in Inches :");
heightMother += input.nextInt();
System.out.print("Enter Father Height in Feet :");
int heightFather = 12* input.nextInt();
System.out.print("Enter Father Height in Inches :");
heightFather += input.nextInt();
estimate = (((heightFather*12/13)+ heightMother)/2);
System.out.print("Estimated Child Height in Feet/Inches: ");
System.out.println((estimate/12)+"/"+(estimate%12));
}
else
{
System.out.println("Try Again");
continue;
}
}
input.close();
}
}