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

LAB1

The document discusses an introductory lab assignment on object oriented programming. It provides 3 programming tasks - to convert inches to meters, days to months and days, and calculate BMI. It includes the code and output for each task.

Uploaded by

amnamuzammil131
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)
6 views4 pages

LAB1

The document discusses an introductory lab assignment on object oriented programming. It provides 3 programming tasks - to convert inches to meters, days to months and days, and calculate BMI. It includes the code and output for each task.

Uploaded by

amnamuzammil131
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 (SWE -103L) SSUET/QR/114

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:
package lab_task;
import java.util.Scanner;
public class Lab_Task {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Input a value for inch: ");
double inches = scanner.nextDouble();
double meters = inches * 0.0254;
System.out.println(inches + " inch is " + meters + " meters.");
scanner.close();
}
}

2023F-BSE-054 LAB1
Object Oriented Programming (SWE -103L) SSUET/QR/114

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:
package lab_task;
import java.util.Scanner;
public class Lab_Task {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Input the number of days: ");
int days = scanner.nextInt();

int months = days / 30;


int remainingDays = days % 30;

System.out.println(days + " days are " + months + " months and " + remainingDays + "
days.");
scanner.close();
}
}

2023F-BSE-054 LAB1
Object Oriented Programming (SWE -103L) SSUET/QR/114

OUTPUT:

3. Write a Java program to compute body mass index (BMI). Note: weigh in
kilogram = weight * 0.45359237. Height in feet= inches * 0.0254. BMI=
weight in kilogram/ (hight in fee)^2.
CODE:
package lab_task;
import java.util.Scanner;
public class Lab_Task {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter weight in pounds: ");


double weightPounds = scanner.nextDouble();
double weightKg = weightPounds * 0.45359237;

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


double heightInches = scanner.nextDouble();
double heightMeters = heightInches * 0.0254;

2023F-BSE-054 LAB1
Object Oriented Programming (SWE -103L) SSUET/QR/114

double bmi = weightKg / (heightMeters * heightMeters);

System.out.println("BMI: " + bmi);

scanner.close();
}
}

OUTPUT:

2023F-BSE-054 LAB1

You might also like