Thursday, October 13, 2011

Creating and Running an Employee Java Application


Creating a Java Application.


You need to create an Employee class that consists of various data members, such as employeeName, employeeAge, employeeSalary, employeeId. The application must initialize the data members to default values when an object of the Employee class is created. In addition, the application must display the data stored in the object.

To solve the above given problem, the things needs to be done.
1. Code the application
2. Compile and execute the application.



Code the Application.
You need to write the code to create an application that consists of the Employee class. The class must contain a constructor that initializes the data members of the class. You also need to define the showData () method that displays the data stored in the object. In addition, you need to define the main () method that creates an object of the Employee class and execute the showData () method.

The below codes create the Employee class and it should be saved as Employee.java


public class Employee
{
   private String employeeName;
   private int employeeAge;
   private float employeeSalary;
   private int employeeId;

public Employee ()
{
   employeeName = "Gino Wine";
   employeeAge = 30;
   employeeSalary = $12,000.00;
   employeeId = E001;
}

public void showData ()
{
   System.out.println ("Employee Name is = "+ employeeName );
   System.out.println ("Employee Age is = "+ employeeAge);
   System.out.println ("Employee Salary is ="+ employeeSalary);
   System.out.println ("Employee Id is ="+ employeeId);
}
public static void main (String args[])
{
   Employee em = new Employee();
   em.showData();
}

}

Compile and Execute the Application

the command to compile the Employee application is
javac Employee.java

the command to execute the application is
java Employee


No comments: