Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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