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

EXPERIMENT NO2java

Uploaded by

techinsighthub12
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)
19 views4 pages

EXPERIMENT NO2java

Uploaded by

techinsighthub12
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

EXPERIMENT NO.

1) Problem Statement : Create a class called Employee that includes three pieces of
information as instance variables first name, a last name and a monthly salary. Your class
should have a constructor that initializes the three instance variables. Provide a set and a get
method for each instance variable. If the monthly salary is not positive, set it to 0.0. Write a test
application named EmployeeTest that demonstrates class Employee's capabilities. Create two
Employee objects and display each object's yearly salary. Then give each Employee a 10% raise
and display each Employee's yearly salary again.

Program:

class Employeedetails {
String Firstname;
String Last name;
float monsalary;
float yearlysalary;
float increasesalary;

Employeedetails(String Firstname, String Last name, float monsalary) {


this.Firstname = Firstname;
this.Lastname = Last name;
this.monsalary = monsalary;
}

void displaydata() {
System.out.println("Employee's Firstname: " + this.Firstname);
System.out.println("Employee's Last name: " + this.Lastname);

if (this.monsalary < 0) {
this.monsalary = 0;
}

yearlysalary = monsalary * 12;


System.out.println("Yearly Salary of Employee: " + yearlysalary);

increasesalary = yearlysalary + yearlysalary * 10 / 100;


System.out.println("Yearly Salary of Employee After Increase: " + increasesalary);
System.out.println();
}

public static void main(String[] args) {


Employeedetails E1 = new Employeedetails("abc", "xyz", 20000);
Employeedetails E2 = new Employeedetails("def", "uvw", 30000);
E1.displaydata();
E2.displaydata();
}
}

Output :
2) Problem Statement : Write a Java Program to demonstrate the use of static variable,
static block and static method.

Program:

public class StaticDemo {


static int count = 0;
static {
System.out.println("Static block is executed.");

public StaticDemo() {
System.out.println("Constructor is called.");
count++;
}
public static void displayCount() {
System.out.println("Count of objects created: " + count);
}
public static void main(String[] args) {

StaticDemo obj1 = new StaticDemo();


StaticDemo obj2 = new StaticDemo();
StaticDemo.displayCount();
}
}

Output :

Conclusion : Students should able to write java program using class and objects.

You might also like