LAB4
LAB4
TASK1:
Code:
public class Employee {
int id;
String name;
String position;
double salary; public class Employee {
int id;
String name;
String position;
double salary;
Output:
Updated Code:
public class Employee {
int id;
String name;
String position;
double salary;
public Employee(int id, String name, String position, double salary) {
this.id = id;
this.name = name;
this.position = position;
this.salary = salary;
}
Output:
Task 2:
}
class Managementsystem{
public static void main(String[] args){
Student student1=new Student("Ali",322);
Student student2=new Student("Ashraf",43242);
for (int i=0;i<7;i++){
student1.addgrade('A');
student2.addgrade('B');
}
student1.studentinfo();
student2.studentinfo();
student1.updategrade(3,'B');
student1.studentinfo();
Output:
TASK3:
Code:
public class Student {
public static class Product {
String name;
int id;
double price;
int quantity;
public void addProduct(String name, int id, double price, int quantity) {
this.name = name;
this.id = id;
this.price = price;
this.quantity = quantity;
}
product1.productInfo();
product2.productInfo();
product1.updateQuantity(5);
product2.updateQuantity(5);
product1.productInfo();
product2.productInfo();
Task 4:
Code:
class Patient {
public static class Pdetail {
String name;
int id;
String condition;
int age;
public void addPatient(String name, int id, String condition, int age) {
this.name = name;
this.id = id;
this.condition = condition;
this.age = age;
}
patient1.patientInfo();
patient2.patientInfo();
patient1.updateCondition("Feeling better");
patient2.updateCondition("Minor Cough");
patient1.patientInfo();
patient2.patientInfo();
if (foundPatient != null) {
System.out.println("Patient found by ID " + searchId + ":");
foundPatient.patientInfo();
} else {
System.out.println("Patient with ID " + searchId + " not found.");
}
}
}
OUTput: