0% found this document useful (0 votes)
77 views4 pages

Assignment 1

This document provides code examples and instructions for 3 Java programming exercises as part of an introductory lab on object-oriented programming. The first exercise converts inches to meters, the second converts days to months and days, and the third calculates body mass index (BMI) based on user-input weight and height. Each exercise includes sample input/output and the Java code to perform the given calculation.

Uploaded by

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

Assignment 1

This document provides code examples and instructions for 3 Java programming exercises as part of an introductory lab on object-oriented programming. The first exercise converts inches to meters, the second converts days to months and days, and the third calculates body mass index (BMI) based on user-input weight and height. Each exercise includes sample input/output and the Java code to perform the given calculation.

Uploaded by

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

Introduction to OOP Lab #1

LAB # 1

INTRODUCTION TO OOP

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

LAB TASK

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.

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 java.util.Scanner;
public class Q1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner number = new Scanner (System.in);
System.out.println("enter value in inches: ");
int num = number.nextInt();
double digit= num*(0.0254);
System.out.println(digit +"meters");

Object Oriented Programming - OOPs 1


Introduction to OOP Lab #1

OUTPUT:

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.

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 java.util.Scanner;
public class Q2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner in = new Scanner(System.in);


System.out.print("Enter days: ");
int days = in.nextInt();

int month = (days % 365) / 30;


days = (days % 365) % 7;

System.out.println("months = " + month);

Object Oriented Programming - OOPs 2


Introduction to OOP Lab #1

System.out.println("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 java.util.Scanner;
public class Q3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Input weight in pounds: ");
double weight = input.nextDouble();

System.out.print("Input height in inches: ");


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:

Object Oriented Programming - OOPs 3


Introduction to OOP Lab #1

Object Oriented Programming - OOPs 4

You might also like