0% found this document useful (0 votes)
44 views7 pages

LAB 1 - Template

The document describes 3 Java programs: 1) Converts inches to meters by multiplying inches by 0.0254. 2) Converts days to months and days by dividing days by 30 for months and taking remainder for days. 3) Calculates body mass index (BMI) by taking weight in pounds multiplied by 0.45359237 divided by height in inches multiplied by 0.0254 squared.

Uploaded by

Sarah Gohar
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)
44 views7 pages

LAB 1 - Template

The document describes 3 Java programs: 1) Converts inches to meters by multiplying inches by 0.0254. 2) Converts days to months and days by dividing days by 30 for months and taking remainder for days. 3) Calculates body mass index (BMI) by taking weight in pounds multiplied by 0.45359237 divided by height in inches multiplied by 0.0254 squared.

Uploaded by

Sarah Gohar
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/ 7

Object Oriented Programming Lab# 01

LAB # 1

OBJECTIVE

To understand Java Environment and Java Data Types.

Question:
Write a java program that reads a number in inches, converts it to meters.

Source Code:
package task1.lab.pkg1;

import java.util.Scanner;

/**
*
* @author Sarah Gohar
*/
public class Task1Lab1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
package task1.lab.pkg1;

import java.util.Scanner;

1 ROLL NO: 2020F-BSE-011


Object Oriented Programming Lab# 01

/**
*
* @author Sarah Gohar
*/
public class Task1Lab1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Please enter inches:");
double inches=sc.nextDouble();
double mtrs=inches*0.0254;
System.out.println("\n'<<<<<Inches are converted into meters>>>>>>>'");
System.out.println("\n'Your converted merters are':");
System.out.println(mtrs);

// TODO code application logic here


}

}
Output:

2 ROLL NO: 2020F-BSE-011


Object Oriented Programming Lab# 01

Question #2
Write a java program to convert days into number of moths and days
Source code:
//program to convert days into number of moths and days
package lab1;

/**
*
* @author Sarah Gohar
*/
public class Lab1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int num = 73;

int days = num % 30;

3 ROLL NO: 2020F-BSE-011


Object Oriented Programming Lab# 01
int month = num / 30;
System.out.println(num + " days = " + month + " Month and " + days + " days");
}
}

// TODO code application logic here


}

}
Output:

Question #3
Write a java program to compute body mass index (BMI)
Source code:
// program to compute body mass index (BMI)
package task.pkg3;
import java.util.Scanner;
package task.pkg3;
4 ROLL NO: 2020F-BSE-011
Object Oriented Programming Lab# 01

/**
*
* @author Sarah Gohar
*/
public class Task3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.print("\t***Program to compute body mass index (BMI)***");
Scanner input = new Scanner(System.in);

System.out.print("\n\n^^^Input weight in pounds^^^: ");


double weight = input.nextDouble();

System.out.print("\n^^^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");
}
}

5 ROLL NO: 2020F-BSE-011


Object Oriented Programming Lab# 01

Output:

6 ROLL NO: 2020F-BSE-011


Object Oriented Programming Lab# 01

7 ROLL NO: 2020F-BSE-011

You might also like