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) {
[Link] = Firstname;
[Link] = Last name;
[Link] = monsalary;
}
void displaydata() {
[Link]("Employee's Firstname: " + [Link]);
[Link]("Employee's Last name: " + [Link]);
if ([Link] < 0) {
[Link] = 0;
}
yearlysalary = monsalary * 12;
[Link]("Yearly Salary of Employee: " + yearlysalary);
increasesalary = yearlysalary + yearlysalary * 10 / 100;
[Link]("Yearly Salary of Employee After Increase: " + increasesalary);
[Link]();
}
public static void main(String[] args) {
Employeedetails E1 = new Employeedetails("abc", "xyz", 20000);
Employeedetails E2 = new Employeedetails("def", "uvw", 30000);
[Link]();
[Link]();
}
}
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 {
[Link]("Static block is executed.");
public StaticDemo() {
[Link]("Constructor is called.");
count++;
}
public static void displayCount() {
[Link]("Count of objects created: " + count);
}
public static void main(String[] args) {
StaticDemo obj1 = new StaticDemo();
StaticDemo obj2 = new StaticDemo();
[Link]();
}
}
Output :
Conclusion : Students should able to write java program using class and objects.