0% found this document useful (0 votes)
27 views

Object Oriented Programming: Objective

The document describes 3 Java programming exercises to practice object-oriented programming concepts. The first exercise has the student write a program to convert inches to meters. The second converts days into months and days. The third computes body mass index (BMI) based on user-input weight in pounds and height in inches. For each exercise, the document provides the programming problem statement, sample input/output, and the Java source code solution.

Uploaded by

Wali Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Object Oriented Programming: Objective

The document describes 3 Java programming exercises to practice object-oriented programming concepts. The first exercise has the student write a program to convert inches to meters. The second converts days into months and days. The third computes body mass index (BMI) based on user-input weight in pounds and height in inches. For each exercise, the document provides the programming problem statement, sample input/output, and the Java source code solution.

Uploaded by

Wali Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming Lab#

01

LAB # 1

OBJECTIVE
To understand OOP(Java Environment),Data Types and Mixed Arthematic Expression.

Question:
1.Write a Java program that reads a number in inches, converts it to meters.
Note: One inch is 0.0254 meter.
Example:
Test Data
Input a value for inch: 1000.
Expected Output:
1000.0 inch is 25.4 meters.

Source Code:
public class HelloWorld
{
public static void main(String[] args)
{
double inch = 1000.0;
double meters = inch * 0.0254;
System.out.println(inch + " inch is " + meters + " meters");

}
}

1 ROLL NO: 2020-SE-216


Object Oriented Programming Lab#
01

Output:

Question:
2.Write a Java program to convert days into number of months and days.
Example:
Test Data
Input the number of days: 69.
Expected Output:
69 days are 2 months and 9 days.

Source Code:
public class HelloWorld
{
public static void main(String[] args)
{
int i = 69;
int month = i / 30;
int days = i % 30;
System.out.println(i + " Days are " + month + " months and " + days + " days");
}
}

2 ROLL NO: 2020-SE-216


Object Oriented Programming Lab#
01

Output:

Question:

3. Write a Java program to compute body mass index (BMI).

Note: weigh in kilogram = weight * 0.45359237.


Hight in feet= inches * 0.0254.
BMI= weight in kilogram/(height in fee)^2.

Source Code:
import java.util.Scanner;
public class HelloWorld
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

System.out.println("Input weight in pounds: ");


double weight = input.nextDouble();
System.out.println("Input height in inches: ");
double inches = input.nextDouble();

double BMI = weight * 0.45359237 / (inches * 0.0254 * inches * 0.0254);


System.out.println("Body Mass Index is " + BMI+"\n");

3 ROLL NO: 2020-SE-216


Object Oriented Programming Lab#
01
}
}
Output:

4 ROLL NO: 2020-SE-216

You might also like