Introduction to OOP Lab #1
LAB # 1
INTRODUCTION TO OOP
OBJECTIVE:
To understand OOP(Java Environment),Data Types and Mixed Arthematic
Expression.
LAB TASK
[Link] 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.
CODE:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q1;
/**
*
* @author Karan kumar
*/
import [Link];
public class Q1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner number = new Scanner ([Link]);
[Link]("enter value in inches: ");
int num = [Link]();
double digit= num*(0.0254);
[Link](digit +"meters");
Object Oriented Programming - OOPs 1
Introduction to OOP Lab #1
OUTPUT:
[Link] 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.
CODE:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q2;
/**
*
* @author Karan kumar
*/
import [Link];
public class Q2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner([Link]);
[Link]("Enter days: ");
int days = [Link]();
int month = (days % 365) / 30;
days = (days % 365) % 7;
[Link]("months = " + month);
Object Oriented Programming - OOPs 2
Introduction to OOP Lab #1
[Link]("Days = " + days);
}
}
OUTPUT:
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/(hight in fee)^2.
CODE:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q3;
/**
*
* @author Karan kumar
*/
import [Link];
public class Q3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner([Link]);
[Link]("Input weight in pounds: ");
double weight = [Link]();
[Link]("Input height in inches: ");
double inches = [Link]();
double BMI = weight * 0.45359237 / (inches * 0.0254 * inches * 0.0254);
[Link]("Body Mass Index is " + BMI+"\n");
}
}
OUTPUT:
Object Oriented Programming - OOPs 3
Introduction to OOP Lab #1
Object Oriented Programming - OOPs 4