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

Mudassir 1

The document is an assignment on Java classes and methods, authored by M Mudassir Khan for an Advanced Programming course. It includes code for a 'Person' class and an 'Employee' class that extends 'Person', demonstrating object-oriented programming concepts. The main class 'Company' creates instances of both classes and showcases their functionalities, such as displaying information and modifying attributes.

Uploaded by

dangerbeast422
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)
5 views4 pages

Mudassir 1

The document is an assignment on Java classes and methods, authored by M Mudassir Khan for an Advanced Programming course. It includes code for a 'Person' class and an 'Employee' class that extends 'Person', demonstrating object-oriented programming concepts. The main class 'Company' creates instances of both classes and showcases their functionalities, such as displaying information and modifying attributes.

Uploaded by

dangerbeast422
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

Assignment No 02

Name: M Mudassir Khan


Roll No.: 2203
Subject: Advanced Programming
Discipline: BS CS 5th Semester
Topic: Java Classes And Methods Use With a Program

Submitted to :
Sir Fareed Ullah
Government Superior Science College Peshawar
// Person class
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void displayInfo() {
System.out.println("Name:Of The Person is "
+ name + ", Age: Of the Person is " + age);
}
public void increaseAge() {
age++;
}
}
// Employee class
public class Employee extends Person {
private String jobTitle;
private double salary;
public Employee(String name, int age, String
jobTitle, double salary) {
super(name, age);
this.jobTitle = jobTitle;
this.salary = salary;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void displayEmployeeInfo() {
displayInfo();
System.out.println("Job Title: " + jobTitle
+ ", Salary: " + salary);
}
public void raiseSalary(double percentage) {
salary *= (1 + percentage / 100);
}
}
// Company class (main class)
public class Company {
public static void main(String[] args) {
// Create Person instance
Person person = new Person("Mudassir", 20);
person.displayInfo();
person.increaseAge();
person.displayInfo();
// Create Employee instance
Employee employee = new Employee("Khan",
25, "Software Engineer", 50000.0);
employee.displayEmployeeInfo();
employee.raiseSalary(10);
employee.displayEmployeeInfo();
}
}

You might also like