D 9 9 import java.util. InputMismatchException; import java.util.Scanner; 9 public class BMI {//class //set values for...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
D 9 9 import java.util. InputMismatchException; import java.util.Scanner; 9 public class BMI {//class //set values for kilo per pound and meters per inch final double KILOGRAMS_PER_POUND= 0.45359237; final double METERS_PER_INCH = 0.0254; //initialize fields private double weight; private double height; private double bmi; //create new object of class Scanner Scanner input = new Scanner(System.in); public BMI (double w, double h, double p, int b){ //begin constructor weight = w; //set value of weight height = h; //set value of height bmi= b; //set value of bmi }//end 3 argument constructor public double getWeight() {//begin method get weight return weight; }//end method getweight public void setWeight (double w) {//begin method set weight if (w > 0) {//if value is greater than 0 weight = w;//set value to weight }else {//end method set weight System.out.println(" Please enter a positive number. "); promptWeight(); //print error message and allow the user to retry entry } }//end method set weight public double getHeight() {//begin method getheight return height; }//end method getHeight public void setHeight (double h) {//begin method setheight if (h> 0) {//if value is over > height = h; //set value to height }else { System.out.println(" Please enter a positive number. "); promptHeight(); //print error message and allow the user to retry entry } }//end method setheight public double getBmi() {//begin method getBMI return bmi; }//end method getHeight public void setBmi (double b) {//begin method setBmi bmi = b; }//end method setBmi bmi = b; }//end method setBmi public void promptWeight() {//begin method promptWeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your weight in pounds: "); setWeight (input.nextDouble()); //validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptWeight public void promptHeight() {//begin method promptHeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculate BMI () {//begin method calculate BMI double weightInKilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment current Year calculatoRMT/\//calculato interact try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatchException ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop } //end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculateBMI() {//begin method calculate BMI double weightInkilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is " + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment currentYear calculateBMI(); //calculate interest System.out.print(toString()); //print the method toString } //end method loop //to string @Override public String toString() { return "your weight is + getWeight() +", your height is + getHeight() + your BMI is }//end to string public static void main(String[] args) {//main method begina BMI bmi new BMI(0, 0, 0, 0); bmi.promptweight(); bmi.promptHeight(); bmi.loop();//invoke method loop System.out.printf(" %s%20s ", "Height", "Weight"); //print column headers }//end method main + getBmi(); }//end class D 9 9 import java.util. InputMismatchException; import java.util.Scanner; 9 public class BMI {//class //set values for kilo per pound and meters per inch final double KILOGRAMS_PER_POUND= 0.45359237; final double METERS_PER_INCH = 0.0254; //initialize fields private double weight; private double height; private double bmi; //create new object of class Scanner Scanner input = new Scanner(System.in); public BMI (double w, double h, double p, int b){ //begin constructor weight = w; //set value of weight height = h; //set value of height bmi= b; //set value of bmi }//end 3 argument constructor public double getWeight() {//begin method get weight return weight; }//end method getweight public void setWeight (double w) {//begin method set weight if (w > 0) {//if value is greater than 0 weight = w;//set value to weight }else {//end method set weight System.out.println(" Please enter a positive number. "); promptWeight(); //print error message and allow the user to retry entry } }//end method set weight public double getHeight() {//begin method getheight return height; }//end method getHeight public void setHeight (double h) {//begin method setheight if (h> 0) {//if value is over > height = h; //set value to height }else { System.out.println(" Please enter a positive number. "); promptHeight(); //print error message and allow the user to retry entry } }//end method setheight public double getBmi() {//begin method getBMI return bmi; }//end method getHeight public void setBmi (double b) {//begin method setBmi bmi = b; }//end method setBmi D 9 9 import java.util. InputMismatchException; import java.util.Scanner; 9 public class BMI {//class //set values for kilo per pound and meters per inch final double KILOGRAMS_PER_POUND= 0.45359237; final double METERS_PER_INCH = 0.0254; //initialize fields private double weight; private double height; private double bmi; //create new object of class Scanner Scanner input = new Scanner(System.in); public BMI (double w, double h, double p, int b){ //begin constructor weight = w; //set value of weight height = h; //set value of height bmi= b; //set value of bmi }//end 3 argument constructor public double getWeight() {//begin method get weight return weight; }//end method getweight public void setWeight (double w) {//begin method set weight if (w > 0) {//if value is greater than 0 weight = w;//set value to weight }else {//end method set weight System.out.println(" Please enter a positive number. "); promptWeight(); //print error message and allow the user to retry entry } }//end method set weight public double getHeight() {//begin method getheight return height; }//end method getHeight public void setHeight (double h) {//begin method setheight if (h> 0) {//if value is over > height = h; //set value to height }else { System.out.println(" Please enter a positive number. "); promptHeight(); //print error message and allow the user to retry entry } }//end method setheight public double getBmi() {//begin method getBMI return bmi; }//end method getHeight public void setBmi (double b) {//begin method setBmi bmi = b; }//end method setBmi bmi = b; }//end method setBmi public void promptWeight() {//begin method promptWeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your weight in pounds: "); setWeight (input.nextDouble()); //validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptWeight public void promptHeight() {//begin method promptHeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculate BMI () {//begin method calculate BMI double weightInKilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment current Year calculatoRMT/\//calculato interact bmi = b; }//end method setBmi public void promptWeight() {//begin method promptWeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your weight in pounds: "); setWeight (input.nextDouble()); //validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptWeight public void promptHeight() {//begin method promptHeight boolean continueLoop = true; //set boolean for looping do { //begin do...while statement try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatch Exception ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop }//end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculate BMI () {//begin method calculate BMI double weightInKilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment current Year calculatoRMT/\//calculato interact try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatchException ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop } //end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculateBMI() {//begin method calculate BMI double weightInkilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is " + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment currentYear calculateBMI(); //calculate interest System.out.print(toString()); //print the method toString } //end method loop //to string @Override public String toString() { return "your weight is + getWeight() +", your height is + getHeight() + your BMI is }//end to string public static void main(String[] args) {//main method begina BMI bmi new BMI(0, 0, 0, 0); bmi.promptweight(); bmi.promptHeight(); bmi.loop();//invoke method loop System.out.printf(" %s%20s ", "Height", "Weight"); //print column headers }//end method main + getBmi(); }//end class try {//begin try statement System.out.print("Please enter your height in inches: "); setHeight (input.nextDouble());//validate amount entered continueLoop = false;//stop the loop } //end try statement catch (InputMismatchException ime) { //begin catch statement System.out.println(" Please enter a valid amount. "); input.nextLine(); //print error message and restart the loop } //end catch statement } while (continueLoop); //end do...while statement } //end method promptHeight public void calculateBMI() {//begin method calculate BMI double weightInkilograms = getWeight() * KILOGRAMS_PER_POUND; double heightInMeters = getHeight()* METERS_PER_INCH; setBmi (weightInKilograms /(heightInMeters * heightInMeters));//calculate BMI System.out.println("BMI is " + bmi); if (getBmi() < 18.5) System.out.println("You are Underweight"); else if (getBmi() < 25) System.out.println("You are Normal"); else if (getBmi() < 30) System.out.println("You are overweight"); else System.out.println("You are Obese");//print BMI } //end method public void loop() { //begin method loop //as long as current Year is less than year continue loop and increment currentYear calculateBMI(); //calculate interest System.out.print(toString()); //print the method toString } //end method loop //to string @Override public String toString() { return "your weight is + getWeight() +", your height is + getHeight() + your BMI is }//end to string public static void main(String[] args) {//main method begina BMI bmi new BMI(0, 0, 0, 0); bmi.promptweight(); bmi.promptHeight(); bmi.loop();//invoke method loop System.out.printf(" %s%20s ", "Height", "Weight"); //print column headers }//end method main + getBmi(); }//end class
Expert Answer:
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
In this question you will be asked to reflect on a project you have been involved in or observed, in which a design evolved, or could have evolved, through applying a theory of user behaviour. You...
-
Data set Theory Assume an informational record with one association parent including matches (a, b) where a can't try not to be a parent of b. (a) Write a Datalog demand which gives the graph of...
-
Blaine is a practicing dentist. He operates his business from the basement of his house, with a separate entrance and facilities. Blaine uses the simplified method every year to calculate his...
-
Assume Robertson, Inc., paid $289,000 to acquire all the common stock of Dinette Corporation and Dinette owes Robertson $197,000 on a note payable. Immediately after the purchase on September 30,...
-
The objective of the directors of Bolton Ltd is to maximise the net cash inflow to the company. The company expects to have spare capacity during the coming year and its directors are considering...
-
How to submit a claim to private arbitration?
-
Tech Systems manufactures an optical switch that it uses in its final product. Tech Systems incurred the following manufacturing costs when it produced 68,000 units last year: Direct...
-
Summary Information from the financial statements of two companies competing in the same Industry follows. Barco Company Kyan Company Barco Company Kyan Company Data from the current year-end balance...
-
Answer- Mike Greenberg opened Swifty Window Washing Co. on July 1, 2020. During July, the following transactions were completed. July 1 Owner invested $14,200 cash in the company. 1 Purchased used...
-
Phoenix Company reports the following fixed budget. It is based on an expected production and sales volume of 15,300 units. PHOENIX COMPANY Fixed Budget For Year Ended December 31 $ 3,213, eee Sales...
-
Explore the impact of circular narratives on storytelling. In what ways do works like "Blood Meridian" by Cormac McCarthy or "Cloud Atlas" by David Mitchell use cyclical patterns to underscore themes...
-
Examine the use of stream-of-consciousness as a narrative structure. How does this technique, employed by authors like Virginia Woolf in "Mrs. Dalloway" or William Faulkner in "The Sound and the...
-
Consider an atom diffuses in a 3 D simple cubic lattice by a random walk mechanism. The atom jumps 6 x 1 0 - 5 times per second at 3 0 0 K and 3 x 1 0 4 times per second at 6 0 0 K . Assuming that...
-
Projectile Motion Practice Questions 1. Tom the cat is chasing Jerry the mouse across a table surface 1.5 m high. Jerry steps out of the way at the last second, and Tom slides off the edge of the...
-
1- Explain aggressive mechanisms to manage interpersonal conflicts. 2-Differentiate between distributive bargaining and integrative negotiation as conflict management techniques. 3-Explain Glasl's...
-
1. Balance equation: Ca + HCl = CaCl2 + H2 2. Balance equation: P2O5 + H2O = H3PO4 3. With the 2 equations determined which are the reactants andwhich are the products.
-
Stephen Schor, an accountant in New York City, advised his client, Andre Romanelli, Inc., to open an account at J. P. Morgan Chase Bank, N.A., to obtain a favorable interest rate on a line of credit....
-
Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on. Only one light...
-
The gcd(m, n) can also be defined recursively as follows: If m % n is 0, gcd(m, n) is n. Otherwise, gcd(m, n) is gcd(n, m % n). Write a recursive method to find the GCD. Write a test program that...
-
Revise Heap in Listing 23.9, using a generic parameter and a Comparator for comparing objects. Define a new constructor with a Comparator as its argument as follows:Heap(Comparator comparator)...
-
What are the main components of corporate directional strategies?
-
Define concept growth. What does this mean to entrepreneurial firms?
-
Discuss the significance of discounting in business decision making.
Study smarter with the SolutionInn App