0% found this document useful (0 votes)
17 views8 pages

LAB4

Uploaded by

Arslan Khan
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)
17 views8 pages

LAB4

Uploaded by

Arslan Khan
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/ 8

Submitted By:

Muhammad Arslan (465428)

TASK1:

Code:
public class Employee {
int id;
String name;
String position;
double salary; 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;
}

public void displayinfo() {


System.out.println("ID : " + id);
System.out.println("Name : " + name);
System.out.println("Position : " + position);
System.out.println("Salary : " + salary);
System.out.println();
}
}
class EmployeeManager {

public static void main(String[] args) {


Employee employe1=new Employee(1234,"Annas Aziz","Director",12000.0);
Employee employe2=new Employee(100023,"Shafiq Nawaz","Deputy
Director",10000.0);
Employee employe3=new Employee(1231231,"Ajmal Majeed","Assisstant
manager",6000.0);
employe1.displayinfo();
employe2.displayinfo();
employe3.displayinfo();
}
}

public Employee(int id, String name, String position, double salary) {


this.id = id;
this.name = name;
this.position = position;
this.salary = salary;
}

public void displayinfo() {


System.out.println("ID : " + id);
System.out.println("Name : " + name);
System.out.println("Position : " + position);
System.out.println("Salary : " + salary);
System.out.println();
}
}
class EmployeeManager {

public static void main(String[] args) {


Employee employe1=new Employee(1234,"Annas Aziz","Director",12000.0);
Employee employe2=new Employee(100023,"Shafiq Nawaz","Deputy
Director",10000.0);
Employee employe3=new Employee(1231231,"Ajmal Majeed","Assisstant
manager",6000.0);
employe1.displayinfo();
employe2.displayinfo();
employe3.displayinfo();
}
}

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;
}

public void displayinfo() {


System.out.println("ID : " + id);
System.out.println("Name : " + name);
System.out.println("Position : " + position);
System.out.println("Salary : " + salary);
System.out.println();
}
}
class EmployeeManager {

public static void main(String[] args) {


Employee employe1=new Employee(111111,"Ahmed Khalid","Assisstant ",2000.0);
Employee employe2=new Employee(100023,"Shafiq Nawaz","Deputy
Director",10000.0);
Employee employe3=new Employee(1231231,"Ajmal Majeed","Assisstant
manager",6000.0);
employe1.displayinfo();
employe2.displayinfo();
employe3.displayinfo();
}
}

Output:
Task 2:

public class Student {


String name;
int rollno;
char[] grades;
int gradescount;

public Student(String name, int rollno) {


this.name = name;
this.rollno = rollno;
this.grades = new char[7];
this.gradescount = 0;
}

public void addgrade(char grade) {


if (gradescount < 7) {
grades[gradescount++] = grade;
} else
System.out.println("MAximum limit reaachd");

public void updategrade(int index, char newGrades) {


if (index >= 0 && index < grades.length) {
grades[index] = newGrades;
System.out.println("Grade updated successfully");
} else
System.out.println("Grade ndex overloaded");
}

public double averagegrade() {


if (gradescount == 0) {
return 0.0;
} else {
double sum = 0;
for (int i = 0; i < gradescount; i++) {
sum += getNumber(grades[i]);
}
return sum / gradescount;
}
}

public int getNumber(char grades) {


switch (grades) {
case 'A':
return 4;
case 'B':
return 3;
case 'C':
return 2;
case 'D':
return 1;
default:
return 0;
}
}

public void studentinfo() {


System.out.println("Student Information");
System.out.println("Name : " + name);
System.out.println("Roll No. : " + rollno);
System.out.println("Grades ");
for (int i = 0; i < gradescount; i++) {
System.out.println(grades[i] + " ");
}
System.out.println();
System.out.println("Average = " + averagegrade());
}

}
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 Product(String name, int id, double price, int quantity) {


this.name = name;
this.id = id;
this.price = price;
this.quantity = quantity;
}

public void addProduct(String name, int id, double price, int quantity) {
this.name = name;
this.id = id;
this.price = price;
this.quantity = quantity;
}

public void updateQuantity(int quantity) {


this.quantity = quantity;
}

public double total() {


return price * quantity;
}

public void productInfo() {


System.out.println("Product Information");
System.out.println("Name: " + name);
System.out.println("Id: " + id);
System.out.println("Quantity: " + quantity);
System.out.println("Total Price: $" + total());
}

public static double grandTotal(Product product1, Product product2) {


return product1.total() + product2.total();
}
}

public static void main(String[] args) {


Product product1 = new Product("Ipad", 121, 5.0, 10);
Product product2 = new Product("Mobile", 2323, 100.0, 20);

product1.productInfo();
product2.productInfo();

product1.updateQuantity(5);
product2.updateQuantity(5);

product1.productInfo();
product2.productInfo();

// Displaying grand total


System.out.println("Grand Total: $" + Product.grandTotal(product1, product2));
}
}
Output:

Task 4:
Code:
class Patient {
public static class Pdetail {
String name;
int id;
String condition;
int age;

public Pdetail(String name, int id, String condition, int age) {


this.name = name;
this.id = id;
this.condition = condition;
this.age = age;
}

public void addPatient(String name, int id, String condition, int age) {
this.name = name;
this.id = id;
this.condition = condition;
this.age = age;
}

public void updateCondition(String newCondition) {


this.condition = newCondition;
}

public void patientInfo() {


System.out.println("Patient Information");
System.out.println("Name: " + name);
System.out.println("Id: " + id);
System.out.println("Age: " + age);
System.out.println("Condition: " + condition);
System.out.println();
}

public Pdetail searchById(int searchId) {


if (this.id == searchId) {
return this;
}
return null;
}
}

public static void main(String[] args) {


Pdetail patient1 = new Pdetail("Junaid", 121, "Typhoid", 10);
Pdetail patient2 = new Pdetail("Kashif", 1254, "Cough", 25);

patient1.patientInfo();
patient2.patientInfo();

patient1.updateCondition("Feeling better");
patient2.updateCondition("Minor Cough");

patient1.patientInfo();
patient2.patientInfo();

// Searching for a patient by ID


int searchId = 121;
Pdetail foundPatient = patient1.searchById(searchId);

if (foundPatient != null) {
System.out.println("Patient found by ID " + searchId + ":");
foundPatient.patientInfo();
} else {
System.out.println("Patient with ID " + searchId + " not found.");
}
}
}
OUTput:

You might also like