You are on page 1of 5

Task No 1:

class employe{
private String name;
private int id;
private double salary;

public employe(String n, int i, double s){


this.name = n;
this.id=i;
this.salary = s;
}

public void setName(String n) {


this.name=name;
}
public void setId(int i) {
this.id=id;
}
public void setSalary(double s) {
this.salary=salary;
}
public void getName(){
System.out.println("name is: " + this.name);
}
public void getId() {
System.out.println("name is: " + this.id);
}
public void getsalary() {
System.out.println("name is: " + this.salary);
}
public void calculateYearlysalary(double s) {
double yearlysalary = s*12;
System.out.println(yearlysalary);
}
}
public class Employee {
public static void main(String[] args) {
// TODO Auto-generated method stub
employe e = new employe("Absar" , 652 , 10000);
e.setName("Absar");
e.setId(652);
e.setSalary(10000);
e.getName();
e.getId();
e.getsalary();
e.calculateYearlysalary(100000);
}
}

Outputt:

Task No 2:
class Student{
private String name;
private int id;
private int age;

public Student(String n, int i, int a){


this.name=n;
this.id=i;
this.age=a;
}

public void setName(String name) {


this.name=name;
}
public void setid(int i) {
this.id=i;
}
public void setAge(int a) {
if(a>0 && a<120) {
this.age=a;
}
else {
System.out.println("Enter a valid age");
}
}
public void getname() {
System.out.println("name is: " + this.name);
}
public void getId() {
System.out.println("ID is: "+this.id);
}
public void getAge() {
System.out.println("Age is: "+ this.age);
}

}
public class Main {
public static void main(String[] args) {
Student s1 = new Student("Sohaib" , 637 , 25);
Student s2 = new Student("Absar" , 652 , 35);
s1.setName("Kabootri");
s1.setAge(25);
s1.setid(668);
s1.getname();
s1.getId();
s1.getAge();
s2.setName("gawachi ghaanh");
s2.setAge(35);
s2.setid(656);
s2.getname();
s2.getId();
s2.getAge();
}
}

Outputt:

You might also like