Skip to main content

Java Program to make Employee Record

Employee Record 





First is the Employee Class:-

public class Employee


 private String firstName; 
 private String lastName; 
 private double monthlySalary; 

 public Employee(String f, String l, double m)
 {
 firstName = f;     
 lastName = l;     
 if(m < 0){
 monthlySalary =0;   
 }     
 else
 {
 monthlySalary = m; 
 }
 }

    public String getFirstName()
{     
return firstName;
    }

    public void setFirstName(String fname)
{
firstName = fname;
    }

    public String getLastName()
{   
return lastName; 

public void setLastName(String lname)
{   
    lastName = lname; 
}

public double getMonthlySalary()
{   
    return monthlySalary; 
}   
    public void setMonthlySalary(double m)
{     
if(m < 0)

monthlySalary =0;     
}     
else
{
monthlySalary = m;
}

}
}



Second is the Main Class To execute the Code :-


import java.util.Scanner;


public class EmployeeTest
 {
 public static void main(String[] args)
 {

 Scanner S = new Scanner(System.in); 
 System.out.println("Enter the first name employee 1 ");
 String fname = S.next();   
 System.out.println("Enter the last name:employee 1 ");
 String lname = S.next();
 System.out.println("Enter the Salary:employee 1 ");
 double sal = S.nextDouble(); 
 Employee e =new Employee(fname,lname ,sal );

System.out.println("the yearly salary of employee 1"+e.getFirstName()+" "   +e.getLastName()+" :");
 System.out.println(e.getMonthlySalary()*12);

double newsalary= e.getMonthlySalary()*0.1+e.getMonthlySalary();     
  e.setMonthlySalary(newsalary);   
  System.out.println("the new yearly salary of employee 1 "+ e.getFirstName()+" "+e.getLastName()+" :");
  System.out.println(e.getMonthlySalary()*12);   
  e.getMonthlySalary();


 System.out.println("Enter the first name employee 2");
  fname = S.next();   
 System.out.println("Enter the last name:employee 2");
 lname = S.next();
 System.out.println("Enter the Salary:employee 2");
 sal = S.nextDouble(); 
 Employee e2=new Employee(fname,lname ,sal );

System.out.println("the yearly salary of employee 2"+e2.getFirstName()+" "   +e2.getLastName()+" :");
 System.out.println(e2.getMonthlySalary()*12);

 newsalary= e2.getMonthlySalary()*0.1+e2.getMonthlySalary();   
  e2.setMonthlySalary(newsalary); 
  System.out.println("the new yearly salary of employee 2"+ e2.getFirstName()+" "+e2.getLastName()+" :");
  System.out.println(e2.getMonthlySalary()*12);   
  e2.getMonthlySalary();

    }
 }

Comments

Popular posts from this blog

Technology

Virtual Reality The Next Upcoming Domain in Pakistan is VIRTUAL REALITY and people are making themselves obsessed with it because it takes your imagination to what you are seeing through VR gadget as we know the technology is going to boom in Pakistan through last few years.

Program to Make Canvas in Java For GUI

GRAPHICAL USER INTERFACE : CANVAS CLASS: import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /**  * Canvas is a class to allow for simple graphical drawing on a canvas.  * This is a modification of the general purpose Canvas, specially made for  * the BlueJ "shapes" example.   *  * @author: Bruce Quig  * @author: Michael Kšlling (mik)  *  * @version 2011.07.31  */ public class Canvas {     // Note: The implementation of this class (specifically the handling of     // shape identity and colors) is slightly more complex than necessary. This     // is done on purpose to keep the interface and instance fields of the     // shape objects in this project clean and simple for educational purposes.     private static Canvas canvasSingleton;     /**      * Factory method to get t...

Virtual reality

VIRTUAL REALITY: A BLESSING INTRODUCTION At the beginning of 1990s the development in the field of virtual reality became much more stormy and the term Virtual Reality itself became extremely popular. We can hear about Virtual Reality nearly in all sort of media, people use this term very often and they misuse it in many cases  too. The reason is that this new, promising and fascinating technology captures greater interest of people than e.g., computer graphics. The consequence of this state is that nowadays the border between 3D computer graphics and Virtual Reality becomes fuzzy.Virtual reality is the creation of a virtual environment presented to our senses in such a way that we experience it as if we were really there. It has both entertainment and serious uses. The technology is becoming cheaper and more widespread. We can expect to see many more innovative uses for the technology in the future and perhaps a fundamental way in which we communicate and work t...