Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks for the user’s height, weight and age, and then comput

ID: 3681357 • Letter: W

Question

Write a program that asks for the user’s height, weight and age, and then computes expected clothing sizes according to the formulas: Hat size = (weight in pounds) divided by (height in inches) and all that multiplied by 2.9. Jacket size (chest in inches) = height times weight divided by 288 then adjusted by adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes place after full 10 years. So, there is no adjustment for years 30 through 39, but 1/8 of an inch is added for age 40.) Waist size (waist in inches) = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.) Create methods for each calculation: hatSize(), jacketSize(), and waistSize() . Think of needed parameters and their types. You can introduce other methods as needed. Your program should allow user to repeat this calculation as often as the user wishes.

Explanation / Answer

java code

ClothingSizes1.java

package org.students;

import java.text.DecimalFormat;
import java.util.Scanner;

public class ClothingSizes1 {

   public static void main(String[] args) {
       DecimalFormat df = new DecimalFormat("#.##");
       Scanner sc = new Scanner(System.in);
       while (true) {
           System.out.print("Enter the Users height(In inches):");
           double height = sc.nextDouble();
           System.out.print("Enter the Users Weight(In Pounds):");
           double weight = sc.nextDouble();
           System.out.print("Enter the Users Age:");
           int age = sc.nextInt();
           double hs = hatSize(weight, height);
           double js = jacketSize(height, weight, age);
           double ws = waistSize(height, weight, age);
           System.out.println("The clothing size for the User's Hat is:"
                   + df.format(hs) + " inches");
           System.out.println("The clothing size for the User's Jacket is:"
                   + df.format(js) + " inches");
           System.out.println("The clothing size for the User's Waist is:"
                   + df.format(ws) + " inches");
           System.out.print("Do you want Enter another user (Y/N):");
           Scanner sc1 = new Scanner(System.in);
           char c = sc1.next(".").charAt(0);
           if (c == 'Y' || c == 'y') {
               continue;
           } else {
               System.out.println("* Program Exit *");
               break;
           }

       }
   }

   private static double hatSize(double weight, double height) {
       double hs = (weight / height) * 2.9;
       return hs;

   }

   private static double jacketSize(double height, double weight, int age) {
       double size;
       int j;
       if (age >= 30) {
           if ((age % 10) != 0)
               age = age - (age % 10);
           j = (age - 30) / 10;
           size = ((height * weight) / 288) + ((1.0 / 8) * j);
       } else
           size = ((height * weight) / 288);

       return size;

   }

   private static double waistSize(double height, double weight, int age) {

       double size2;
       int k;
       if (age >= 28) {
           if ((age % 2) != 0)
               age = age - (age % 2);
           k = (age - 28) / 2;
           size2 = (weight / (5.7)) + ((1.0 / 10) * k);
       } else
           size2 = weight / (5.7);
       return size2;

   }

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------

output:

Enter the Users height(In inches):67
Enter the Users Weight(In Pounds):240
Enter the Users Age:45
The clothing size for the User's Hat is:10.39 inches
The clothing size for the User's Jacket is:55.96 inches
The clothing size for the User's Waist is:42.91 inches
Do you want Enter another user (Y/N):

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

C++ code

#include<iostream>
using namespace std;

double hatSize(double weight, double height);
double jacketSize(double height, double weight, int age);
double waistSize(double height, double weight, int age);
   int main()
   {
       double height ;
       char c ;
       double weight;
       int age=0;
       while (true) {
           cout<<"Enter the Users height(In inches):";
           cin>>height;
           cout<<"Enter the Users Weight(In Pounds):";
           cin>> weight;
       cout<<"Enter the Users Age:";
           cin>>age;
           double hs = hatSize(weight, height);
           double js = jacketSize(height, weight, age);
           double ws = waistSize(height, weight, age);
           cout<<"The clothing size for the User's Hat is:"
                   << hs << " inches ";
           cout<<"The clothing size for the User's Jacket is:"
                   << js << " inches ";
           cout<<"The clothing size for the User's Waist is:"
                   << ws << " inches ";
           cout<<"Do you want Enter another user (Y/N):";
          
           cin>>c;
           if (c == 'Y' || c == 'y') {
               continue;
           } else {
               cout<<"* Program Exit *";
               break;
           }

       }
   }

   double hatSize(double weight, double height) {
       double hs = (weight / height) * 2.9;
       return hs;

   }

   double jacketSize(double height, double weight, int age) {
       double size;
       int j;
       if (age >= 30) {
           if ((age % 10) != 0)
               age = age - (age % 10);
           j = (age - 30) / 10;
           size = ((height * weight) / 288) + ((1.0 / 8) * j);
       } else
           size = ((height * weight) / 288);

       return size;

   }

   double waistSize(double height, double weight, int age) {

       double size2;
       int k;
       if (age >= 28) {
           if ((age % 2) != 0)
               age = age - (age % 2);
           k = (age - 28) / 2;
           size2 = (weight / (5.7)) + ((1.0 / 10) * k);
       } else
           size2 = weight / (5.7);
       return size2;

   }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote