0% found this document useful (0 votes)
220 views2 pages

A Simple Case Study: Import Java - Io.

This document describes a case study involving two Java classes: Employee and EmployeeTest. The Employee class defines an employee with instance variables for name, age, designation, and salary. It contains a constructor that takes a name parameter and methods to set the other variable values and print employee details. The EmployeeTest class creates two Employee objects and calls methods on each to assign values and test the Employee class functionality.

Uploaded by

Nazeeh Rzeqat
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)
220 views2 pages

A Simple Case Study: Import Java - Io.

This document describes a case study involving two Java classes: Employee and EmployeeTest. The Employee class defines an employee with instance variables for name, age, designation, and salary. It contains a constructor that takes a name parameter and methods to set the other variable values and print employee details. The EmployeeTest class creates two Employee objects and calls methods on each to assign values and test the Employee class functionality.

Uploaded by

Nazeeh Rzeqat
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/ 2

import java.io.

*;

A Simple Case Study


For our case study, we will be creating two classes. They are Employee and
EmployeeTest.
First open notepad and add the following code. Remember this is the Employee
class and the class is a public class. Now, save this source file with the name
Employee.java.
The Employee class has four instance variables - name, age, designation and
salary. The class has one explicitly defined constructor, which takes a
parameter.
Example
import java.io.*;
public class Employee {

String name;
int age;
String designation;
double salary;

// This is the constructor of the class Employee


public Employee(String name) {
this.name = name;
}

// Assign the age of the Employee to the variable age.


public void empAge(int empAge) {
age = empAge;
}

/* Assign the designation to the variable designation.*/


public void empDesignation(String empDesig) {
designation = empDesig;
}

/* Assign the salary to the variable salary.*/


public void empSalary(double empSalary) {
salary = empSalary;
}

/* Print the Employee details */


public void printEmployee() {
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Designation:" + designation );
System.out.println("Salary:" + salary);
}
}

As mentioned previously in this tutorial, processing starts from the main method.
Therefore, in order for us to run this Employee class there should be a main
method and objects should be created. We will be creating a separate class for
these tasks.
Following is the EmployeeTest class, which creates two instances of the class
Employee and invokes the methods for each object to assign values for each
variable.
Save the following code in EmployeeTest.java file.

You might also like