-1

I need the program to print out a statement providing the child adult height in a decimal format of feet (using the modulus) (for ex if the child's height is 5'7" the display should read "The child's adult height would be 5.58'

    import java.text.NumberFormat;
    import java.util.Scanner;


    public class Workshop3GenderModification {


    public static void main(String[] args) {

int gender;
gender = 'M';
gender = 'F';
double cheight=0;

Scanner input = new Scanner(System.in);

//father height

    System.out.print("Enter your father height in feet ");
    int ffeet=input.nextInt();

System.out.print("Enter father height in inches ");

int finches=input.nextInt();

//mother height

System.out.print("Enter mother height in feet ");
    int mfeet=input.nextInt();

System.out.print("Enter mother height in inches ");

int minches=input.nextInt();
int mheight = mfeet * 12 + minches;
int fheight = ffeet * 12 + finches;

// child gender

System.out.print("Enter M for male or F for female ");
    gender = input.next().charAt (0);

// male or female

input.nextLine();

switch (gender){
    case 'M':
    case 'm':  
        cheight =(int)((fheight * 13/12.0)+ mheight)/2;
        break;
    case 'F' :
    case 'f' : 
        cheight =(int)((mheight * 12/13.0) + fheight)/2 ;
        break;
    default:  
        System.out.print("Invalid entry.  Please enter only M,F,m or f.  ");  
        break;
}

int cfeet= (int)cheight/12;
int cinched= (int)cheight%12;
double aheight=(cfeet/cinched);

System.out.print(cfeet +"'" + cinched + "\"");

System.out.printf(" will be the adult child's height." +" %.2f", aheight);


   }

}
Lisa
  • 1
  • 1
  • 2
  • Not sure what you are asking but I guess you are asking about integer division i.e. `1/2 == 0` not `0.5` change `cfeet` to a double – Scary Wombat Feb 20 '17 at 04:29
  • sorry! I'm so new to this I don't even really know how to formulate my questions. The output from this program is giving me this: ("6'2" will be the adult child's height. 3.00") when I need the output to convert the child's height to a decimal format of feet displaying like this: " 5.58' " – Lisa Feb 20 '17 at 04:35
  • why `5.58` -how do you calculate this? what result are you getting? – Scary Wombat Feb 20 '17 at 04:38
  • I think it's a problem with this code specifically: int cfeet= (int)cheight/12; int cinched= (int)cheight%12; For example if a child's height is 5'7" = 60 inches plus 7 inches = 67 inches/12 = 5.58 I'm sure it's not the most logical program, hence my difficulty understanding – Lisa Feb 20 '17 at 04:40
  • @ScaryWombat I am guessing that 5 feet 7 inches is 5 feet plus (7/12 = 0.58...) because there are 12 feet in an inch. – David Choweller Feb 20 '17 at 04:41
  • so just an Integer division problem then, see my first comment – Scary Wombat Feb 20 '17 at 04:43
  • @Lisa If you want decimal format output, I'm not sure why you're using integer division and the modulo operator. – David Choweller Feb 20 '17 at 04:44
  • To get the decimal output, you probably want `double aheight= (cheight/12.0)`. I would check, but I believe dividing by a float or double causes Java to use regular division, instead of integer division. – David Choweller Feb 20 '17 at 04:48
  • 1
    What is the point of calculating `cfeet/cinched`? It looks like if someone is 5'11", you'll get 0.4545 (except for the integer division problem); if someone is 6'1", the result will be 6; and if someone is an even 6 feet, i.e. 6'0"--what will happen then? What are you hoping to accomplish with this calculation? – ajb Feb 20 '17 at 04:50
  • @Lisa please update your question with information like what input program is expecting , expected output ... This will help you get better answers solutions to your problem. – RamPrakash Feb 20 '17 at 17:37

1 Answers1

0

I have modified just one line in your program. Instead of

double aheight=(cfeet/cinched);

I have added

double aheight=(cheight/12.0);

What you had didn't really make sense if you wanted to provide the feet and inches as a decimal value.

import java.util.Scanner;


public class Workshop3GenderModification {


    public static void main(String[] args) {

        int gender;
        gender = 'M';
        gender = 'F';
        double cheight=0;

        Scanner input = new Scanner(System.in);

        //father height

        System.out.print("Enter your father height in feet ");
        int ffeet=input.nextInt();

        System.out.print("Enter father height in inches ");

        int finches=input.nextInt();

        //mother height

        System.out.print("Enter mother height in feet ");
        int mfeet=input.nextInt();

        System.out.print("Enter mother height in inches ");

        int minches=input.nextInt();
        int mheight = mfeet * 12 + minches;
        int fheight = ffeet * 12 + finches;

        // child gender

        System.out.print("Enter M for male or F for female ");
        gender = input.next().charAt (0);

        // male or female

        input.nextLine();

        switch (gender){
            case 'M':
            case 'm':  
                cheight =(int)((fheight * 13/12.0)+ mheight)/2;
                break;
            case 'F' :
            case 'f' : 
                cheight =(int)((mheight * 12/13.0) + fheight)/2 ;
                break;
            default:  
                System.out.print("Invalid entry.  Please enter only M,F,m or f.  ");  
                break;
        }

        int cfeet= (int)cheight/12;
        int cinched= (int)cheight%12;
        double aheight=(cheight/12.0);

        System.out.print(cfeet +"'" + cinched + "\"");

        System.out.printf(" will be the adult child's height." +" %.2f", aheight);


    }

}
David Choweller
  • 1,060
  • 1
  • 8
  • 7