Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

A-08_KAUSHIKI_KULAKARNI

ASSIGNEMNT 1(TSDL-JAVA)
Q. Create a class Person and add the following data members to it: Name, height, weight, age,
dailyExercise(yes/no).

Write the following member methods: calculateBMI(height, weight)

fitnessLevel(age, dailyExercise, BMI): Based on the person's age and whether he/she exercises or
not,  print fitnessLevel as output. E.g. if age < 50, dailyexercise=true and BMI < 25, then the person is
fit.

In your main program, create an instance of Person class, call both the functions and demonstrate their
behavior by providing different param values. i.e. call the functions multiple times with different
values.

Code:-

import java.util.Scanner;
class Person{

     double calculateBMI(double height,double weight)



     double BMI = weight / (height * height);
     System.out.println("\nThe Body Mass Index (BMI) is " + BMI + " kg/m2");
     return BMI;
}

void fitnesslevel(int age,int dailyExercise,double BMI)


{
    if(dailyExercise == 1)
  {
       System.out.println("dailyExcersise=True");
  }
    else
  {
        System.out.println("dailyExcersise=False");
  }
    if((age<50) && (BMI<25))
  {
        System.out.println("You are Fit");
  }
    else
  {
        System.out.println("You are not Fit.You need Motivation");
  }
}
  
    public static void main(String[] args)
  {
        String name;
A-08_KAUSHIKI_KULAKARNI

        double height;
        double weight;
        int age;
        int dailyExercise;

        Person p1 = new Person();


        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Your Name: ");
        name = sc.nextLine();
        System.out.println("Input weight in kilogram: ");
        weight = sc.nextDouble();
        System.out.println("Input height in meters: ");
        height = sc.nextDouble();  
        System.out.println("Input DailyExcercise(1/0): ");
        dailyExercise = sc.nextInt();
        System.out.println("Input Age in Years: ");
        age = sc.nextInt();
        // p1.calculateBMI(height,weight);
        double Bmi = p1.calculateBMI(height,weight);
        p1.fitnesslevel(age,dailyExercise,Bmi);
  }
}

Output:-

You might also like