Professional Documents
Culture Documents
LAB1
LAB1
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();
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);
2023F-BSE-054 LAB1
Object Oriented Programming (SWE -103L) SSUET/QR/114
scanner.close();
}
}
OUTPUT:
2023F-BSE-054 LAB1