🔒 Closed Bmi calculator with classes

Status
Not open for further replies.

Kuroneko - chan

Journeyman
Code:
import java.util.*;

public class BmiClasses
{
    public static void main(String[] args)
    {
        BmiClasses a = new BmiClasses();
        a.option();
    }
    
    public void option(){
        Compute a = new Compute();
        Scanner in = new Scanner(System.in);
        double c, d;
        System.out.println("Enter choice: \n1:Metric Unit \n2:Imperial Unit");
        int x = in.nextInt();
        
        if(x == 1){
            System.out.println("Enter weight in kilo: ");
            c = in.nextDouble();
            System.out.println("Enter height in meter: ");
            d = in.nextDouble();
            a.metric(c,d);
            a.identify();
            option();
        }
        else if(x == 2){
            System.out.println("Enter weight in pounds: ");
            c = in.nextDouble();
            System.out.println("Enter height in inches: ");
            d = in.nextDouble();
            a.imperial(c,d);
            a.identify();
            option();
        }
        else{
            System.out.println("Invalid choice: " + x);
            option();
        }
    }
}

class Compute{
    double bmi;
    public void metric(double c, double d){
        bmi = c / (d * d);
        System.out.println("Your Body Mass Index: " + bmi);
    }
    public void imperial(double c, double d){
        final int z = 703;
        bmi = (z * c) / (d * d);
        System.out.println("Your Body Mass Index: " + bmi);
    }
    public void identify(){
        if(bmi < 18.5){
            System.out.println("You are Underweight");
        }
        else if(bmi >= 18.5 - 24.9){
            System.out.println("You are Normal and Healty");
        }
        else if(bmi >= 25 - 29.9){
            System.out.println("You are Overweight");
        }
        else if(bmi >= 30){
            System.out.println("You are Obese");
        }
        else{
            System.out.println("You are not a Human");
        }
    }
}

Or download here:
You do not have permission to view the full content of this post. Log in or register now.
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 1K
    Views
  • 4
    Participants
Last reply from:
Maria Malumanay

Trending Topics

Online now

Members online
1,069
Guests online
858
Total visitors
1,927

Forum statistics

Threads
2,274,946
Posts
28,959,527
Members
1,233,492
Latest member
PHC-Francis
Back
Top