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

Object Oriented Programming: Objective

This document provides instructions and code examples for 3 Java programs. The first program converts inches to meters. The second program converts days to months and remaining days. The third program calculates body mass index (BMI) based on a user's weight in kilograms and height in meters. Each program includes test input/output examples and the Java code to perform the given calculation.

Uploaded by

Rauf Creators
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Object Oriented Programming: Objective

This document provides instructions and code examples for 3 Java programs. The first program converts inches to meters. The second program converts days to months and remaining days. The third program calculates body mass index (BMI) based on a user's weight in kilograms and height in meters. Each program includes test input/output examples and the Java code to perform the given calculation.

Uploaded by

Rauf Creators
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object Oriented Programming Lab# 01

LAB # 1

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

Program1
Object

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.

Coding
import java.util.Scanner;
public class pg1 {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input a value for inch: ");
double inch = input.nextDouble();
double meters = inch * 0.0254;
System.out.println(inch + " inch are equal to " + meters + " meters");
}
}

OUTPT
Object Oriented Programming Lab# 01
Program2
Object

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.

Coding
import java.util.Scanner;
public class pg2
{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("Enter No Of Days: ");
int no = input.nextInt();
int days = no%30;
int month = no/30;
System.out.println(no+" days = "+month+" Month and "+days+" days");
}
}

OUTPUT
Object Oriented Programming Lab# 01
Program3
Object

Coding
import java.util.Scanner;
public class pg3 {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input weight: ");
double weight = input.nextDouble();
System.out.print("Input height: ");
double inches = input.nextDouble();
double BMI = weight * 0.45359237 / (inches * 0.0254 * inches * 0.0254);
System.out.print("Body Mass Index is " + BMI+"\n");
}
}

OUTPUT

You might also like