Question

In: Computer Science

In this activity, we are going to implement the previous algorithm in Java. Just in case,...

In this activity, we are going to implement the previous algorithm in Java. Just in case, here is problem again: This program calculates and displays a person's body mass index (BMI). The BMI is calculated as the weight times 703 divided by the height squared where the weight is measured in pounds and the height in inches. The program should display a message indicating whether the person has optimal weight (BMI between 18.5 and 25), is underweight (BMI is less than 18.5), or overweight (BMI is greater than 25).

Important considerations:

1. There are several ways to design and implement this algorithm; however, for the purpose of this exercise and for an automatic grading, we are going to use the algorithm developed in the previous exercise.

2. Because of the softchalk limitation about the uses of double quotation marks, and for uniformity, the String objects have been created for you.

3. For the calculation, you must use the Math library for the exponentiation.

4. The curly braces for the if-else statement blocks are located in separate lines for uniformity.

Given the following skeleton, please add the missing instructions

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner scan = new Scanner(System.in);

double weight;

double height;

double bmi;

String stWeight = "Enter your weight (pounds) ";

String stHeight = "Enter your height (inches) ";

String stBMI = "Your BMI is ";

String stOver = "You are considered Overweight";

String stOptimal = "You have optimal weight";

String stUnder = "You are considered Underweight";

Fill in: ALL OF THE BLANKS HAVE TO BE FILLED IN!!

//Input prompt the user for weight and height in that order

System.out.println(stWeight);
System.out.println(stHeight);

//Calculate BMI

// Display results of calculation and the message in different lines

//Overweight

//Optimal Weight

//Underweight

}

Solutions

Expert Solution

CODE FOR THE FOLLOWING PROGRAM:-

import java.util.Scanner;    // Import the Scanner class
import java.lang.Math;          //Import the math class
public class Main
{
  public static void main (String[]args)
  {

    // TODO Auto-generated method stub

    Scanner scan = new Scanner (System.in);

    double weight;

    double height;

    double bmi;

    String stWeight = "Enter your weight (pounds) ";

    String stHeight = "Enter your height (inches) ";

    String stBMI = "Your BMI is ";

    String stOver = "You are considered Overweight";

    String stOptimal = "You have optimal weight";

    String stUnder = "You are considered Underweight";

      //Input prompt the user for weight and height in that order
      System.out.println(stWeight);
      weight=scan.nextDouble();
      
      System.out.println(stHeight);
      height=scan.nextDouble();
    //Calculate BMI Formula: 703 x weight (lbs) / [height (in)]2

      bmi = (703 * weight) / Math.pow(height, 2);
    // Display results of calculation and the message in different lines

      //Underweight
    if (bmi <= 18.5)
      {
        System.out.println (stUnder);
      }
       //Optimal Weight
    else if (bmi > 18.5 && bmi < 25)
      {
        System.out.println (stOptimal);
      }
    //Overweight
    else if (bmi >= 25)
      {
        System.out.println (stUnder);
      }
  }
}

SCREENSHOT OF THE PROGRAM AND SAMPLE OUTPUT:-

SAMPLE OUTPUT:-

HAPPY LEARNING


Related Solutions

Please write a Java algorithm solving the following problem: Implement a Java method to check if...
Please write a Java algorithm solving the following problem: Implement a Java method to check if a binary tree is balanced. For this assignment, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. 1. First, please create the following two classes supporting the Binary Tree Node and the Binary Tree: public class BinTreeNode<T> { private T key; private Object satelliteData; private BinTreeNode<T> parent;...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) Requirements Choose one problem with an algorithm and implement it. You should show and explain the result whatever you got. I recommend using N-Queen problem (at least N=8 or more) or any simple perfect games. For example, - N-Queen problem with hill climbing - N-Queen problem with simulated annealing - N-Queen problem with genetic algorithm - Tic-Tac-Toe with Minimax
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) N-Queen problem with genetic algorithm Please use the N-Queen problem (at least N=8 or more) or any simple perfect games. Please provide a screenshot of output and please heavily comment the code. Thanks!
implement this crypto algorithm: Compare observed performance differences and differences in the implementation techniques. just implement...
implement this crypto algorithm: Compare observed performance differences and differences in the implementation techniques. just implement a crypto algorithm
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should...
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should be implemented: Constant space, i.e. without creating extra copies of the linked list Unrestricted space q1: / For this implementation you should use constant space   // Note: you are free to add any extra methods,   // but this method has to be used   public static boolean isPalindromeRestricted(ListNode head) {     // Your code goes here     return false;   } q2: // For this implementation the space...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in class: 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with different quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the...
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array...
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array of integers into ascending order. Consider the given array as input and produce a sorted array as output. Each time you take an integer from the input array, place it at the end of the output array. If the result is unsorted, backtrack.
We started creating a Java class for Car. In this lab we are going to complete...
We started creating a Java class for Car. In this lab we are going to complete it in the following steps: 1- First create the Car class with some required instance variables, such make, model, year, price, speed, maxSpeed, isOn, isMoving, and any other properties you like to add. 2- Provide couple of constructors for initializing different set of important properties, such as make, model, year, and price. Make sure that you do not repeat initialization of instance variables in...
Based on the scenario above, implement the Huffman coding algorithm using Java NetBeans. Assume the characters...
Based on the scenario above, implement the Huffman coding algorithm using Java NetBeans. Assume the characters and frequencies as listed below. The total number of nodes is n = 6.
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending...
Hello i need someone to implement in JAVA a radix sort algorithm forsorting strings in ascending order. The input to your algorithm should be a (multi)set S = [S1, S2, . . . , Sn] of strings each of which is of length m over the English alphabet [A…Z, a…z]. The output should be the set sorted in ascending lexicographical order. Number of strings is >= 100 and number of characters >= 50 i need the answer fast please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT