MADANAPALLE INSTITUTE OF TECHNOLOGY AND SCIENCES
NAME:- M DEEPTHI
ROLL NO:-24691A0598
CLASS AND SECTION:-CSE B
TEACHER NAME:- SOWMYA DEVI
SET-3
Write a program that calculates the Body Mass Index (BMI) by taking weight and height as
input from the user. The program should ensure that weight and height are positive and height
is not zero. It should perform type casting if needed, calculate BMI, classify it into
underweight, normal, overweight, or obese categories based on standard thresholds, and
display the results using formatted output.
Create a class Rectangle with attributes length and width.
Write methods calculateArea() and calculatePerimeter().
Write a method scaleRectangle(Rectangle r, double factor) to scale dimensions of the
rectangle passed as an object.
Demonstrate passing objects by reference and show that changes persist outside the
method.
Display area and perimeter before and after scaling.
1) import [Link];
public class BMICheck
{
public static void main(String[] args)
{
Scanner input = new Scanner([Link]);
[Link]("Enter your weight (kg): ");
double w = [Link]();
[Link]("Enter your height (m):
");
double h = [Link]();
if (w > 0 && h > 0) {
double value = w / (h * h);
String status;
if (value < 18.5) {
status = "Underweight";
} else if (value < 25) {
status = "Normal";
} else if (value < 30) {
status = "Overweight";
} else {
status = "Obese";
}
[Link]("Your BMI is %.2f and you are classified as %s
%n", value, status);
} else {
[Link]("Please provide positive values for
both weight and height.")
;
}
[Link]();
}
}
2A)
import [Link];
Public class ShapeTest {
Public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link](“Length: “);
Double l = [Link]();
[Link](“Width: “);
Double w = [Link]();
Rect r = new Rect(l, w);
[Link](“Initial measurements:”);
[Link](“Area = “ + [Link]());
[Link](“Perimeter = “ + [Link]());
[Link](“Enter scale factor: “);
Double f = [Link]();
[Link](r, f);
[Link](“After resizing:”);
[Link](“Area = “ + [Link]());
[Link](“Perimeter = “ + [Link]());
[Link]();
}
}
Class Rect {
Double len;
Double wid;
Rect(double l, double w) {
Len = l;
Wid = w;
}
Double area() {
Return len * wid;
}
Double perimeter() {
Return 2 * (len + wid);
}
Static void resize(Rect r, double factor) {
[Link] *= factor;
[Link] *= factor;
}
}