Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Comparable Suppose you have a pre-existing class Dieter that models a person trying to monitor diet and weight to improve his/her Body Mass Index (BMI)

image text in transcribed
Comparable Suppose you have a pre-existing class Dieter that models a person trying to monitor diet and weight to improve his/her Body Mass Index (BMI) rating. The class has the following data and behavior: Field/Constructor/Method Description private String name the dietet's full name, such as "John Smith" private int height the dieter's height, in inches private int weight the dieter's weight, in pounds public Dieter(String name, int h, int w) makes a dieter with given name, height, weight public String getName returns the dieter's name public int getHeight returns the dieter's height public int getWeight returns the dieter's weight public double getBMIO computes the dieter's Body Mass Index (BMI). which is (weight/ height2) - 703 public void gain(int pounds) called when the dieter gains weight public void lose(int pounds) called when the dieter lose weight We want Dieter objects comparable to each other using the Comparable interface based on: Dicters are primarily compared by their BMI ratings: A dieter with a lower BMI is less than one with a higher BMI. If two dieters have the same BMI, the tie is broken by height, the shorter person is considered to be "less than the taller one. If two dieters have the same BMI and height, the tie is broken by name. The dieter whose name comes first in alphabetical order is considered "less than the one whose name comes later in ABC order If the two dieters have the same BMI, height, and name, they are considered to be "equal" Due to the class header from the pvious question, this comparable class is required to contain a specific method. Fill in the boxes below with the appropriate tokens that make up the required method's header: d)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions